Changeset 191 for trunk/trax/trax.php

Show
Ignore:
Timestamp:
03/24/06 09:37:59 (6 years ago)
Author:
haas
Message:

Window support, symbol substitution

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/trax.php

    r185 r191  
    2323define("SOURCE_DIR", "@DATA-DIR@/PHPonTrax/data/"); 
    2424 
     25/** 
     26 *  Symbol substitution tables 
     27 * 
     28 *  $search and $replace below are used to perform substitutions of 
     29 *  symbols in a file being copied.  $search is an array of 
     30 *  Perl-compatible regular expressions, and $replace is a congruent 
     31 *  array of replacements for RE matches.  So everywhere that the RE 
     32 *  in, for example, $search[3] is matched in a file, the matching 
     33 *  string is replaced by the contents of $replace[3]. 
     34 */ 
     35$search = array( 
     36                '@TRAX-CONFIG@' // symbol for the full filesystem path 
     37                                // to the Trax config/ directory in 
     38                                // the user's work area 
     39                ); 
     40 
     41$replace = array( 
     42                 ''             // actual value of the full filesystem 
     43                                // path to the Trax config/ directory 
     44                                // in the user's work area 
     45                 ); 
     46 
     47 
    2548function trax() { 
    2649 
     
    4063    $dstdir = $GLOBALS['argv'][1]; 
    4164 
    42     //  Guarantee it ends with '/' 
    43     if (substr($dstdir,-1,1) != '/') { 
    44         $dstdir .= '/'; 
     65    //  Guarantee it ends with DIRECTORY_SEPARATOR 
     66    if (substr($dstdir,-1,1) != DIRECTORY_SEPARATOR) { 
     67        $dstdir .= DIRECTORY_SEPARATOR; 
    4568    } 
    4669    if (!create_dir($dstdir)) { 
    4770        return; 
    4871    } 
     72 
     73    //  Assign real values for symbol substitution 
     74    $replace[0] = $dstdir.'config'; // actual value of the full 
     75                                    // filesystem path to the Trax 
     76                                    // config/ directory in the user's 
     77                                    // work area  
    4978 
    5079    $srcdir = SOURCE_DIR; 
     
    120149 
    121150            //  Destination file does not exist.  Create it 
    122             if (!copy($src_path . $src_file, $dst_path . $src_file)) { 
     151            if (!copy_file($src_path . $src_file, $dst_path . $src_file)) { 
    123152                return false; 
    124153            } 
     
    141170 
    142171            //  Recursive call to copy directory 
    143             if (!copy_dir($src_path . $src_file.'/', 
    144                           $dst_path . $src_file . '/')) { 
     172            if (!copy_dir($src_path . $src_file . DIRECTORY_SEPARATOR, 
     173                          $dst_path . $src_file . DIRECTORY_SEPARATOR)) { 
    145174                return false; 
    146175            } 
     
    165194 
    166195            //  A destination directory with this name exists. 
    167             echo "$dst_dir/ exists\n"; 
     196            echo "$dst_dir".DIRECTORY_SEPARATOR." exists\n"; 
    168197            return true; 
    169198        } 
     
    185214        return false; 
    186215    } 
    187     echo "$dst_dir/ created\n"; 
     216    echo "$dst_dir".DIRECTORY_SEPARATOR." created\n"; 
    188217    return true; 
    189218} 
    190219 
    191220/** 
     221 *  Copy a Trax file into user's work area, substituting @TRAX-...@ 
     222 * 
     223 *  @param string $src_path  Path to source file 
     224 *  @param string $dst_path  Path to destination file 
     225 *  @return boolean true=>success, false=>failure. 
     226 */ 
     227function copy_file($src_path, $dst_path) { 
     228 
     229    //  Read source file into a string 
     230    if (!$file = file_get_contents($src_path)) { 
     231        return false; 
     232    } 
     233 
     234    //  Substitute @TRAX-...@ symbols for appropriate values 
     235 
     236    //  Write out file contents 
     237    @file_put_contents($dst_path, $file); 
     238    return true; 
     239} 
     240 
     241/** 
    192242 *  Output a Usage message and exit 
    193243 */ 
    194244function usage() { 
    195     echo <<<END 
    196 Usage: @BIN-DIR@/trax /path/to/your/app 
     245    echo "Usage: @BIN-DIR@".DIRECTORY_SEPARATOR."trax" 
     246        ." ".DIRECTORY_SEPARATOR."path".DIRECTORY_SEPARATOR."to" 
     247        .DIRECTORY_SEPARATOR."your".DIRECTORY_SEPARATOR."app 
    197248 
    198249Description: 
     
    201252 
    202253Example: 
    203     trax /var/www/html 
    204  
    205     This generates a skeletal Trax installation in /var/www/html. 
     254    trax ".DIRECTORY_SEPARATOR."var".DIRECTORY_SEPARATOR."www" 
     255        .DIRECTORY_SEPARATOR."html 
     256 
     257    This generates a skeletal Trax installation in " 
     258    .DIRECTORY_SEPARATOR."var".DIRECTORY_SEPARATOR."www" 
     259    .DIRECTORY_SEPARATOR."html. 
    206260    See the README in the newly created application to get going. 
    207  
    208 END; 
     261\n"; 
    209262    exit; 
    210263}