imgtools/imaker/buildrom_plugins/plugincommon.pm
changeset 1 be27ed110b50
child 584 56dd7656a965
equal deleted inserted replaced
0:044383f39525 1:be27ed110b50
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Symbian Foundation License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 # Common buildrom plugin methods, for parsing Symbian IBY entries etc.
       
    16 #
       
    17 
       
    18 
       
    19 
       
    20 package plugincommon;
       
    21 
       
    22 use strict;
       
    23 use warnings;
       
    24 
       
    25 use constant FILESPECSTATEMENT => qr/^\s*(\S+?)\s*[=\s]\s*(?:"(.+?)"|(\S+))\s+(?:"(.+?)"|(\S+))(\s+.+?)?\s*$/;
       
    26 
       
    27 use constant FILESPECKEYWORD =>
       
    28     qr/^(?:data|file|primary|secondary|variant|device|extension|dll|filecompress|fileuncompress)/i;
       
    29 
       
    30 use constant FILEBITMAPSPECKEYWORD =>
       
    31     qr/^(?:data|file|primary|secondary|variant|device|extension|dll|filecompress|fileuncompress|BITMAP|AUTO-BITMAP|COMPRESSED-BITMAP)/i;
       
    32 
       
    33 use constant ROFSFILESPECKEYWORD => qr/^(?:data|file|filecompress|fileuncompress)/i;
       
    34 
       
    35 use constant ROFSBITMAPFILESPECKEYWORD => qr/^(?:data|file|filecompress|fileuncompress|BITMAP|AUTO-BITMAP|COMPRESSED-BITMAP)/i;
       
    36 
       
    37 
       
    38 BEGIN
       
    39 {
       
    40     use Exporter();
       
    41     our ($VERSION, @ISA, @EXPORT);
       
    42     $VERSION = 1.00;
       
    43     @ISA     = qw(Exporter);
       
    44     @EXPORT  = qw(
       
    45         FILESPECSTATEMENT FILESPECKEYWORD FILEBITMAPSPECKEYWORD ROFSFILESPECKEYWORD ROFSBITMAPFILESPECKEYWORD
       
    46         &dprint &plugin_init &plugin_start &plugin_end &parse_keyline &parse_obyline
       
    47         &is_entry &get_type_from_entry &get_source_from_entry &get_target_from_entry
       
    48         $gPluginname $gLogfile $gDebug $gHandlestr
       
    49         $gLine $gLnum $gRomid $gKeyword $gSource $gTarget $gAttrib);
       
    50     $| = 1;
       
    51 }
       
    52 
       
    53 our ($gPluginname, $gLogfile, $gDebug, $gHandlestr) = ("", "", "", 0);
       
    54 our ($gLine, $gLnum, $gRomid, $gKeyword, $gSource, $gTarget, $gAttrib) = ("", 0, 0, "", "", "", "");
       
    55 my  $duration = 0;
       
    56 
       
    57 sub dprint($$)
       
    58 {
       
    59     my ($log, $str) = @_;
       
    60     $str =~ s/\n//g;
       
    61     $str = ($log < 0 ? "Warning: " : "") . "$str\n";
       
    62     $log = abs($log);
       
    63     print($str) if (($log == 1) && !$gDebug) || (($log == 2) && $gDebug) || ($log > 2);
       
    64     print(LOG $str) if $gLogfile && ($log > 1);
       
    65 }
       
    66 
       
    67 sub plugin_init($$;$)
       
    68 {
       
    69     ($gPluginname, $gDebug, my $start) = @_;
       
    70     $gDebug = "" if !defined($gDebug);
       
    71     $gDebug =~ s/^(?:(.*?);|(.*))//;
       
    72     $gLogfile = (defined($1) ? $1 : $2);
       
    73     my $warn = "";
       
    74     (open(LOG, ">>$gLogfile") or
       
    75         ($warn = "Can't write to `$gLogfile'.", $gLogfile = "")) if $gLogfile;
       
    76     dprint(3, "$gPluginname: " . ($start ? "-" x (77 - length($gPluginname)) :
       
    77         "Initializing; logfile = `$gLogfile', debug = " . ($gDebug ? 1 : 0)));
       
    78     dprint(-3, $warn) if $warn;
       
    79     close(LOG) if !$start;
       
    80 }
       
    81 
       
    82 sub plugin_start($$)
       
    83 {
       
    84     $duration = time();
       
    85     plugin_init(shift(), shift(), 1);
       
    86     ($gHandlestr, $gLnum, $gRomid) = ("REM handled $gPluginname:", 0, 0);
       
    87 }
       
    88 
       
    89 sub plugin_end()
       
    90 {
       
    91     my $msg = "$gPluginname: Duration: " . (time() - $duration) . " seconds ";
       
    92     dprint(3, $msg . "-" x (79 - length($msg)));
       
    93     close(LOG);
       
    94 }
       
    95 
       
    96 sub get_keyline($)
       
    97 {
       
    98     my $quote = shift();
       
    99     ($gKeyword, $gSource, $gTarget, $gAttrib) =
       
   100         ($1, defined($2) ? ($quote ? "\"$2\"" : $2) : $3, defined($4) ? ($quote ? "\"$4\"" : $4) : $5, defined($6) ? $6 : "");
       
   101 }
       
   102 
       
   103 sub parse_keyline($;$)
       
   104 {
       
   105     ($gLine = shift()) =~ s/^\s+|\s+$//g;
       
   106     get_keyline(shift()), return(1) if $gLine =~ FILESPECSTATEMENT;
       
   107     return(0);
       
   108 }
       
   109 
       
   110 sub parse_obyline($;$)
       
   111 {
       
   112     ($gLine = shift()) =~ s/^\s+|\s+$//g;
       
   113     $gLnum++;
       
   114     $gRomid = $1, return(2) if $gLine =~ /^REM\s+ROM_IMAGE\[(\d+)\]/i;
       
   115     return(-1) if $gLine eq "" || $gLine =~ /^(?:#|REM\s)/i;
       
   116     return(parse_keyline($gLine, shift()));
       
   117 }
       
   118 
       
   119 
       
   120 ###############################################################################
       
   121 #
       
   122 
       
   123 sub is_entry
       
   124 {
       
   125   my $entry = shift;
       
   126   if ($entry =~ /\s*(\S+)\s*=\s*(?:"(.+?)"|(\S+))\s+(?:"(.+?)"|(\S+))/i)
       
   127   {
       
   128     return 1;
       
   129   }
       
   130   return 0;
       
   131 }
       
   132 
       
   133 # get the type from an iby entry
       
   134 sub get_type_from_entry($)
       
   135 {
       
   136   my $entry = shift;
       
   137   if ($entry =~ /\s*(\S+)\s*=\s*(?:"(.+?)"|(\S+))\s+(?:"(.+?)"|(\S+))/i)
       
   138   {
       
   139     return $1;
       
   140   }
       
   141   return "";
       
   142 }
       
   143 
       
   144 # get the source file from an iby entry
       
   145 sub get_source_from_entry($)
       
   146 {
       
   147   my $entry = shift;
       
   148   if ($entry =~ /\s*(\S+)\s*=\s*(?:"(.+?)"|(\S+))\s+(?:"(.+?)"|(\S+))/i)
       
   149   {
       
   150     return defined($2) ? "\"$2\"" : $3;
       
   151   }
       
   152   return "";
       
   153 }
       
   154 
       
   155 # get the target file from an iby entry
       
   156 sub get_target_from_entry($)
       
   157 {
       
   158   my $entry = shift;
       
   159   if ($entry =~ /\s*(\S+)\s*=\s*(?:"(.+?)"|(\S+))\s+(?:"(.+?)"|(\S+))/i)
       
   160   {
       
   161     return defined($4) ? "\"$4\"" : $5;
       
   162   }
       
   163   return "";
       
   164 }
       
   165 
       
   166 1;
       
   167 
       
   168 __END__ # OF PLUGINCOMMON.PM