📄 options.pl
字号:
#!/usr/bin/perl
#*____________________________________________________________________________*\
#*
#
# Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
#
# These sources, libraries and applications are
# FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
# as long as the following conditions are adhered to.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
#
#*____________________________________________________________________________*|
#*
#* $Source: /cvsroot/pi3web/Pi3Web_200/Source/Scripts/options.pl,v $
#* $Date: 2003/05/13 18:42:18 $
#*
# Description:
# Create config.mak file by leading user through menu of build options
#
# LATER, lots of commented out prints in here, should clean it all out
# when I know this works %100
#*____________________________________________________________________________*/
#/*___________________________________________________________________________*\
# Global declarations:
#\*___________________________________________________________________________*/
$debug = 0;
$default_optionsfile = 'options.cnf';
$_=$0;
s/([\/|\\])*options\.pl//i;
if ( length==0 )
{ $_ = '.'; };
&do_main( $_, 'config.mak' );
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
# main
#\*___________________________________________________________________________*/
sub do_main
{
( $in_path, $out_path ) = @_;
local( %arches, %oses, %compilers, %builds,
$arch, $os, $compiler, $build );
#
# zero/create output file
#
open( OUT, '>'.$out_path ) || die "Cannot open file $out_path $!\n";
close( OUT );
#
# Select an architecture
#
$in_path = &concatenate_options( $in_path, "Options", $out_path );
%arches = &read_options( $in_path.'/'.'os.in', %arches );
$arch = &select_option( "available machine architectures", %arches );
print "\n";
#
# Select an operating system
#
$in_path = &concatenate_options( $in_path, $arch, $out_path );
%oses = &read_options( $in_path.'/'.'os.in', %oses );
$os = &select_option( "available operating systems", %oses );
print "\n";
#
# Select a compiler
#
$in_path = &concatenate_options( $in_path, $os, $out_path );
%compilers = &read_options( $in_path.'/'.'os.in', %compilers );
$compiler = &select_option( "available compilers", %compilers );
print "\n";
#
# Select build options
#
$in_path = &concatenate_options( $in_path, $compiler, $out_path );
%builds = &read_options( $in_path.'/'.'os.in', %builds );
$build = &select_option( "build configurations", %builds );
print "\n";
#
$in_path = &concatenate_options( $in_path, $build, $out_path );
print "Machine architecture: \'$arches{$arch}\'\n";
print "Operating system: \'$oses{$os}\'\n";
print "Compiler: \'$compilers{$compiler}\'\n";
print "Build configuration: \'$builds{$build}\'\n";
#
exit 0;
};
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
# read an options file into a hash
#\*___________________________________________________________________________*/
sub read_options
{
local( $file, %hash ) = @_;
open( INP, '<'.$file ) || die "Cannot open file $file $!\n";
while( <INP> )
{
if ( /^\#(.*)/ )
{ next; };
next unless s/^(.*):\s*(.*)\n*//;
$hash{$1} = $2;
};
close( INP );
return %hash;
};
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
# Make the user select an option from a hash, return the key
#\*___________________________________________________________________________*/
sub select_option
{
local( %hash, $i, @tmp );
( $desc, %hash ) = @_;
for(;;)
{
print "Please select one of the following $desc:-\n\n";
@tmp = ();
$i = 1;
foreach $os ( keys %hash )
{
print "\t$i...$hash{$os}\n";
push( @tmp, $os );
$i++;
};
print "\n";
$_ = $i - 1; print "Select [1..$_]> ";
while( <STDIN> )
{
s/(.*)\n$/$1/g;
if ( $_>0 && $_<$i )
{ return $tmp[$_-1]; };
print "Invalid option \'$_\'\n";
last;
};
};
};
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
# Concatenate the options.cnf file in the subdirectory to the main
# options file.
#\*___________________________________________________________________________*/
sub concatenate_options
{
local( $in_path, $option, $out_path ) = @_;
open( OUT, '>>'.$out_path ) || die "Cannot open file $out_path $!\n";
#
# get the root of the key
#
local( $path, $tmp );
$tmp = &find_root( $option );
$_ = $tmp;
if ( !length )
{
#
# the key specified is a directory name only
#
$in_path = $in_path.'/'.$option;
$path = $in_path.'/'.$default_optionsfile;
}
else
{
#
# the key specified is a filename in a directory
#
$path = $in_path.'/'.$option;
$in_path = $in_path.'/'.$tmp;
};
&recursive_concatenate_options( $path, OUT );
close( OUT );
return $in_path;
};
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
#\*___________________________________________________________________________*/
sub recursive_concatenate_options
{
local( $in_path, $out ) = @_;
local( $inp ) = $in_path;
print "path='$in_path', in='$inp', out='$out'\n" if $debug;
open( $inp, '<'.$in_path ) ||
die "Could not open input file: '$in_path'\n";
while( <$inp> )
{
#
# See if this is an include line
#
if ( /^include(\s)*'(.*)';.*$/i )
{
s/^(\w*)(\s*)'(.*)';(.*)\n$/$3/;
print $out "# including file '".$_."'\n";
$file = $_;
&recursive_concatenate_options(
&find_root( $in_path ).'/'.$file, $out );
}
else
{
print $out $_;
};
};
close( $inp );
};
#/*___________________________________________________________________________*\
# *
# Function:
# Synopsis:
# Description:
#\*___________________________________________________________________________*/
sub find_root
{
local( $path ) = @_;
$_ = $path;
if ( /.*\/.*/ )
{
s/(.*)\/(.*)/$1/;
return $_;
}
else
{
return "";
};
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -