Reading command line arguments and setting up values if option not provided
I have a C++ program. I read command line arguments, but if the value is not supplied, I default or make a calculation. Let's say I set it to a default value.
I can code this in several ways. Here I show three ways. What would be the best way for maintaining this code? The program will get very large with lot of options, so need a scheme that can facilitate the development and maintenance of the code .
Code:
Parsing Pc(argc, argv); // Pass all arguments
const double DefdAng = 2.0;
double dAng = DefdAng;
if (Pc.GetDouble("DANG", dAng)) { // User supplied value for dAng using DANG option.
cout << "User supplied dAng value = " << dAng << endl;
}
Code:
Parsing Pc(argc, argv); // Pass all arguments
const double DefdAng = 2.0;
double dAng;
if (Pc.GetDouble("DANG", dAng)) { // User supplied value for dAng using DANG option.
cout << "User supplied dAng value = " << dAng << endl;
else {
dAng = DefdAng;
cout << "dAng set to default value of " << dAng << endl;
}
Code:
Parsing Pc(argc, argv); // Pass all arguments
const double DefdAng = 2.0;
double dAng;
if (!Pc.GetDouble("DANG", dAng)) {
dAng = DefdAng;
cout << "dAng set to default value of " << dAng << endl;
else { // User supplied value for dAng using DANG option.
cout << "User supplied dAng value = " << dAng << endl;
}
If no arguments are entered I wanna be able to read 2 arguments, i have done like this but it doesnt work:
x=0
until #loop starts
do
if ; then
echo No arguments were entered, please enter 2 arguments.
read $1 $2
elif || ; then
echo $#... (0 Replies)
Hi
I want to give the user the choice of whether or not they want to include a certain option when they run the script.
This is my getops:
while getopts " s: d: r f: e h " option
do
case $option in
f ) dsxfile="$OPTARG";;
d ) dbname="$OPTARG";;
s ) dsn="$OPTARG";;
r )... (0 Replies)
Hi,
I am creating a program with the C language that simulates the WC command in Unix. My program needs to count lines, bytes and words. I have not added the code to count bytes and words yet. I am having trouble understanding what the file option/flag '-' does. I can not visualize how it moves... (1 Reply)
Hi all!
I have a data set in this tab separated format : Label, Value1, Value2
An instance is "data.txt" :
0 1 1
-1 2 3
0 2 2
I would like to parse this data set and generate two files, one that has only data with the label 0 and the other with label -1, so my outputs should be, for... (1 Reply)
Hello,
I would like to ask for help with csh script.
An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
I need to develop a script where I will take two date arguments as parameter date1 and date2 which will in format YYYYMM.
Below is the input file say sample.txt.
sample.txt will have certain blocks starting with P1.
Each block will have a value 118,1:TIMESTAMP.
I need to compare the... (7 Replies)
Hi all,
Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE.
for pa in PA_VALUE
blah blah
do
for pb in PB_VALUE
blah blah
do
I have a text file with two columns of values for PA and PB.
14.5 16.7
7.8 9.5
5.6 3.6
etc etc
I would like to read this... (7 Replies)
I want to read properties from a file and print evaluated values of each key.
I am using AIX6.1.
myfile.props
protocol=http
siteA.host=siteAhostname
pageA=pageNameA
siteAURL1=${protocol}:/${siteA.host}/pagea/blabla?v1=32
siteAURL2=${protocol}:/${siteA.host}/${pageA}/blabla?v1=32... (5 Replies)
Discussion started by: kchinnam
5 Replies
LEARN ABOUT DEBIAN
aerpa
aegis -Remove_Project_Alias(1) aegis -Remove_Project_Alias(1)NAME
aegis remove project alias - remove a project alias
SYNOPSIS
aegis -Remove_Project_Alias [ option... ] project-alias
aegis -Help
aegis -VERSion
DESCRIPTION
The aegis -Remove_Project_Alias command is used to remove a project alias.
The project alias must be given on the command line, the default project is not sufficient.
Example
Aliases may be used in may ways. The most common is to give a particular release a code name. You would do this by saying
aenpa example.4.2 sydney
This would make "sydney" an alias for the "example.4.2" branch.
Another use for aliases is to have a fixed alias for your active branch, so that your developer team does not need to change their default
project, even though the branch number moves on for each release. You could say
aenpa example.4.2 example.cur
This would make "example.cur" an alias for the "example.4.2" branch. When this was finished, and 4.3 started, a project administrator
could say
aerpa example.cur
aenpa example.4.3 example.cur
Now "example.cur" is an alias for the "example.4.3" branch, but the developers need only reference "example.cur" to always work on the
right branch.
OPTIONS
The following options are understood:
-Help
This option may be used to obtain more information about how to use the aegis program.
See also aegis(1) for options common to all aegis commands.
All options may be abbreviated; the abbreviation is documented as the upper case letters, all lower case letters and underscores (_) are
optional. You must use consecutive sequences of optional letters.
All options are case insensitive, you may type them in upper case or lower case or a combination of both, case is not important.
For example: the arguments "-project, "-PROJ" and "-p" are all interpreted to mean the -Project option. The argument "-prj" will not be
understood, because consecutive optional characters were not supplied.
Options and other command line arguments may be mixed arbitrarily on the command line, after the function selectors.
The GNU long option names are understood. Since all option names for aegis are long, this means ignoring the extra leading '-'. The
"--option=value" convention is also understood.
ERRORS
It is an error if the current user is not a project administrator.
It is an error if the given name is not a project alias.
EXIT STATUS
The aegis command will exit with a status of 1 on any error. The aegis command will only exit with a status of 0 if there are no errors.
ENVIRONMENT VARIABLES
See aegis(1) for a list of environment variables which may affect this command. See aepconf(5) for the project configuration file's
project_specific field for how to set environment variables for all commands executed by Aegis.
SEE ALSO aenpa(1)
Create a new project alias.
COPYRIGHT
aegis version 4.24.3.D001
Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Peter
Miller
The aegis program comes with ABSOLUTELY NO WARRANTY; for details use the 'aegis -VERSion License' command. This is free software and you
are welcome to redistribute it under certain conditions; for details use the 'aegis -VERSion License' command.
AUTHOR
Peter Miller E-Mail: millerp@canb.auug.org.au
//* WWW: http://www.canb.auug.org.au/~millerp/
Reference Manual Aegis aegis -Remove_Project_Alias(1)