⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gen_config.pl

📁 MMI层OBJ不能完全编译
💻 PL
📖 第 1 页 / 共 2 页
字号:
#!../perl -w
#----------------------------------------------------------------------------- 
#  Project :  
#  Modul   :  gen_config.pl
#----------------------------------------------------------------------------- 
#  Copyright 2004 Texas Instruments
#             All rights reserved. 
# 
#             This file is confidential and a trade secret of Texas 
#             Instruments Nice
#             The receipt of or possession of this file does not convey 
#             any rights to reproduce or disclose its contents or to 
#             manufacture, use, or sell anything it may describe, in 
#             whole, or in part, without the specific written consent of 
#             Texas Instruments Nice. 
#----------------------------------------------------------------------------- 
#  Purpose :  This file generate master.cfg file for ABC and configdef files for BuSyB
#
# The input files must match with the following names and available in the
# working directory:
# - var_def.txt : This file contains the variables, the associated CFG file,
#   and if this one is exported for ABC (the file is usefull only to generate
#   master.cfg file)
# - <variant type>_configs_tcs<program Id>.txt  : These files contain the list of variants and
#   for each variant, the list of variables with their value
#
# File format:
# 
# var_def.txt:
# <Variable name><Spaces><CFG file name>[<Spaces>EXPORTED]
# ...
#
#
# <variant type>_configs_tcs<program Id>.txt:
# <Config name><Spaces><Comments>
# ...
# \[SECTION\]<Spaces>
# [INCLUDE<Spaces><Config name>]
# ...
# <Variable name><Spaces><Value>
# ...
# \[SECTION\]<Spaces>
# [INCLUDE<Spaces><Config name>]
# ...
# <Variable name><Spaces><Value>
# ...
#
# Note that <program Id> must be only numbers
#----------------------------------------------------------------------------- 


use strict;
#use Cwd;
use Getopt::Long qw(:config pass_through);
use Tie::IxHash;


#-------------------------------------------------------------------------------
# Variables
#-------------------------------------------------------------------------------

# Option that is passed in the command line
my $g_options = "";

# Filename of the file which contain the list of variables and associated CFG file + EXPORTED option
my $g_var_def_txt = "var_def.txt";

# Pattern for input file definition
my $g_input_file_name_pattern = "*_configs_tcs*.txt";

# List of files that must be parsed
my @g_configs_xxx_txt = 0;

# Contain per variable the name of the CFG file where variable is defined and the info to
# know if this variable is exported or not
# Used only for ABC; for BuSyB the mapping is contained in the XML file 'configset.xml'
# Keys of the hash table are as follow:
# <variable> = "<cfg file>:<export>"
my %g_abc_variables;

# List of variables per config 
# Keys of the hasch table are as follow:
# "<key>_<configname> = "<filename>:<comment>:<var1>:<value1>: ... :<varn>:<valuen>")
# <key> is <pre>_TCSxx; <pre> and 'xx' come from <pre>_configs_tcsxx.txt
tie %main::g_configs_definition, "Tie::IxHash";

#-------------------------------------------------------------------------------
# Main Program
#-------------------------------------------------------------------------------

# parse command line, passing through all unknown options to make
parse_command_line();

# Check files validity
check_files_validity();

# Ask for variant file if needed
if ($g_options eq "none")
{
   ask_variant_file();
}

# Store informations in global var from input file
store_informations();

# Generate master.cfg file
edit_master_cfg();

# Generate Configdefs files
# edit_configdefs_files();

# Generate files for batch build (L1)
edit_batch_build_files();

#-------------------------------------------------------------------------------
# SUBROUTINES
#-------------------------------------------------------------------------------

#################################
### parse_command_line subroutine
#################################
sub parse_command_line
{
   my $o_all;
   my $o_config_file = "";
   my $o_help;
   
   # Get option list
   my $result = GetOptions ("all"=>\$o_all,
                            "p=s"=>\$o_config_file,
                            "help|h"=>\$o_help);
 
   # If option is -h or more than one option, display tool usage
   if ( $result != 1 || $#ARGV == 0 || $o_help || ($o_all && $o_config_file ne "") )
   {
      usage();
      print "\nPlease press a key to exit ...";
      <STDIN>;
      exit(0);
   }
   
   # if -all option is used
   if ($o_all)
   {
      $g_options = "all";
   }
   # if -p is used, save config file to parse
   elsif ($o_config_file ne "")
   {   
      $g_options = $o_config_file;
   }   
   # If no options
   else
   {
      $g_options = "none";
   }
}

###############################
### ask_variant_file subroutine
###############################
sub ask_variant_file
{
   my $i=0;
   my $choice = 0;
   my $display_menu = 1;
   
   while ($display_menu)
   {
      print "\nPlease choose a file in the list (Id)";

      # Display the list of existing variant files
      $i = 0;

      print "\n0 - All configuration files";
      foreach my $file (@g_configs_xxx_txt)
      {
         $i++;
         print "\n$i - $file";
      }
      print "\n\nYour choice : ";

      # Get the choice from standart IO
      $choice = <STDIN>;
      
      if ($choice !~ /^[0-9]+$/ || $choice < 0 || $choice >$i)
      {
         print "\nChoice not available ...\n\n";
      }
      else
      {
         $display_menu = 0;
      }
   }
   if ($choice != 0)
   {
      # Store the file that have to be parsed
      my $saved_file = $g_configs_xxx_txt[$choice-1];
      @g_configs_xxx_txt = ();
      
      push (@g_configs_xxx_txt, $saved_file);
   }
}

#####################################
### parse_var_def_txt_file subroutine
#####################################
sub parse_var_def_txt_file
{
   my $line;
   
   # Parse var_def.txt file
   open (IN, "<$g_var_def_txt")
     or die "ERROR: could not open file $g_var_def_txt" ;
   
   while ($line = <IN>)
   {
      # Replace list of space character by one space character
      $line =~ s/ +/ /g;
      # Remove CR - LF char
      $line =~ s/\r*\n$// ;

      my @data = split(/ /, $line);
      # Check if there are no more three elements
      if ($#data > 2)
      {
         close(IN);
         error_message("Unexpected string in file \"$g_var_def_txt\"")
      }
      
      if (defined $data[0] && defined $data[1])
      {
         # Store Variable -> CFG file
         $g_abc_variables{$data[0]} = $data[1].":";

         # Check if a third element exists
         if ($#data == 2 && $data[2] ne "")
         {
            if ($data[2] ne "EXPORTED")
            {
               close(IN);
               error_message("Expected EXPORTED and not $data[2]")
            }
            else
            {
               $g_abc_variables{$data[0]} .= $data[2];
            }
         }
         else
         {
            $g_abc_variables{$data[0]} .= "NOT_EXPORTED";
         }
      }
   }
   close(IN);
}


#################################
### store_informations subroutine
#################################
sub store_informations
{
   my $line;
   my $number_of_config;
   my @config_list;

   # Parse list of variants files
   foreach my $config_file (@g_configs_xxx_txt)
   {
      my $section_found = 0;
      
      # Get program number from the file name
      $config_file =~ m/([^_]+)_.+tcs[^0-9]*([0-9]+)/ ;
      
      # Define key to retrieve informations relative to a specific key
      my $key = uc($1)."_TCS$2";
   
      open (IN, "<$config_file")
        or die "ERROR: could not open file $config_file" ;
         
      while ($line = <IN>)
      {
         # Remove CR-LF char and first spaces if there are
         $line =~ s/ *\r*\n$// ;
         $line =~ s/^\s*//;
         # Replace list of space character by one space character
         $line =~ s/ +/ /g;
         
         if ($line ne "")
         {
            # Check if line starts with [SECTION]
            if ($line =~ /^\[SECTION\]/ || $section_found)
            {
               if ($line =~ /^\[SECTION\]/)
               {
                  # Get list of configurations name
                  @config_list = split(/ /, $line);
                  
                  # Store number of configurations
                  $number_of_config = $#config_list;

                  my $i = 0;
                  while ($i < $number_of_config)
                  {
                     $i++;
                     if (!exists($main::g_configs_definition{$key."_$config_list[$i]"}))
                     {
                        $main::g_configs_definition{$key."_$config_list[$i]"} = $config_file."::";
                     }
                  }

                  $section_found = 1;
               }
               # Else we get the list of variables and their values
               else
               {
                  my @data = split(/ /, $line);
                  
                  if ($#data != $number_of_config)
                  {
                     error_message("Number of variables incorrect");
                  }
                  
                  my $i = 0;
                  while ($i < $number_of_config)
                  {
                      $i++;
                      $main::g_configs_definition{$key."_$config_list[$i]"} .= $data[0].":".$data[$i].":";
                  }
               }
            }
            else
            {
               # Store filename and comment
               # $1: config; $2: comment
               $line =~ /([^ ]+) +(.+)/;
               $main::g_configs_definition{$key."_$1"} = $config_file.":"."$2:";
            }
         }
      }
      close (IN);
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -