paramBuild.php 2.76 KB
<?php

/** @file paramBuild.php
*   @brief parameter generator from templates and parameter name
*   @version $Id: $
*   @date Tue Sep 11 14:04:55 CEST 2007
*/

/*
*  To exclude crazy stuff from parameter name
*/

 function param2dd($paramID)
    {
     $pairs = array("-" => "_", "%" => "_","\\" => "_","$" => "_",":" => "_","+" =>" _","-" => "_","#" => "_","@" => "_", "." => "_",">" => "_", "<" => "_");    
     return strtr($paramID, $pairs); 
   }

/*
* Object -> Stuff for DD Graph
*/
    function paramBuild($paramID)
    {
       
           $TargetDir = "./";     //  WHERE CREATE???
           $PRODIR = TEMPLATES;   
           $LIBDIR = PREDEFINED; // predefined ext params

           $ddParamID = param2dd($paramID);
           $paramFunc = strtolower($ddParamID);
                    
               $SED = "sed 's/NEWPARAM/".$paramID."/g' ".$PRODIR."newparam_init.pro | sed 's/DDPARAM/".$ddParamID."/g' > ".$TargetDir.$paramFunc."_init.pro";
               system($SED);
          
               $SED = "sed 's/NEWPARAM/".$paramID."/g' ".$PRODIR."newparam_com.pro | sed 's/DDPARAM/".$ddParamID."/g' > ".$TargetDir.$paramFunc."_com.pro";
               system($SED);
  
               $SED = "sed 's/DDPARAM/".$ddParamID."/g' ".$PRODIR."getnewparam.pro > ".$TargetDir."get".$paramFunc.".pro";
               system($SED);

/*
*            Add predefined functions if exists
*/
             foreach (glob($LIBDIR."*".$paramFunc."*.pro") as $filename) 
                              copy($filename, str_replace($LIBDIR, $TargetDir, $filename));          
                      
     }

/*
*   components
*/
    function paramBuildComp($paramID, $comp)
    {
	   $TargetDir = "./";     //  WHERE CREATE???
           $PRODIR = TEMPLATES;  
	   $ddParamID = param2dd($paramID);
	   $paramFunc = strtolower($ddParamID).'_'.$comp;

	   $SED = "sed 's/DDPARAM/".$ddParamID."/g' ".$PRODIR."newparam_XXX_init.pro | sed 's/XXX/".$comp."/g' > ".$TargetDir.$paramFunc."_init.pro";
	  system($SED);

   }
/* 
*  Real Parameter
*/
 
  function paramBuild_($paramID)
    {
         
          
           $TargetDir = "./";     //  WHERE CREATE???
           $PRODIR = TEMPLATES;  
           $LIBDIR = PREDEFINED; // predefined ext params

           $ddParamID = param2dd($paramID);
           $paramFunc = strtolower($ddParamID);

/*
* Add predefined functions if exists  
*/   
           if (file_exists($LIBDIR.$paramFunc."_.pro")) copy($LIBDIR.$paramFunc."_.pro",$TargetDir.$paramFunc."_.pro");
           else
              {               
                $SED = "sed 's/NEWPARAM/".$paramID."/g' ".$PRODIR."newparam_.pro | sed 's/DDPARAM/".$ddParamID."/g' > ".$TargetDir.$paramFunc."_.pro";
                system($SED);
             }          
     }                                                               
?>