, , , , ,

[SOLVED] Csci 4547 / 6647 program 4b: getopt_long()

$25

File Name: Csci_4547___6647_program_4b__getopt_long__.zip
File Size: 395.64 KB

5/5 - (1 vote)

1 Goals
1. To finish program 4 by including and processing long options.
2 Instructions
Write a program to parse the command line for DiskSweeper. Due Sept. 22 (Friday).
Add to your Params class. Members of the class should include:
• A bool variable for the debug option and an int for the optional level number.
• A bool variable for the verbose option.
Define a controller class named Sweeper. Private data members of the Sweeper class should
include:
• A Params object.
• Move the ofstream from the Params class to the Sweeper class.
Public members of the Params class should include:
• A constructor that accepts argc and argv from main. This constructor must pass argc and
argv to the Params constructor using a ctor. The Params constructor will parse the command
line and initialize the Params object.
• A run() function: Call this from main after declaring the Sweeper object. For now, it should
simply call Params::print() to display the params. More functionality will be added later.
• Any other functions you need. You will be adding members to this class each week.
In your main function:
• Call banner() from tools.cpp.
• Create a Sweeper object.
• Call its run function.
• Nothing else.
3 Using getopt_long() to Decode Command-line Arguments
You still need nearly all of what you wrote for Program 4a. Here are the changes. For more
guidance, refer to options2.c
• The call has two more parameters:
int = getopt_long( int argc, char* argv[], const char* opts,
struct option longOpts[], int*);
• You must pick up and process any additional options and arguments.
• You need to define a long options table. Example:
struct option longOpts[] = {
{ “verbose”, no_argument, NULL, ’b’ },
{ “output”, required_argument, NULL, ’o’ },
{ “recursive”, no_argument, NULL, ’R’ },
{ “debug”, optional_argument, NULL, 0 },
{ NULL, 0, NULL, 0 }
};
• Add this statement to your switch to process long options (such as debug) that do not have
corresponding short options.
case 0: { // Convert code for long switch to full name.
outputLong(longOpts[code].name, optarg);
break;
};
• After all switches have been processed, pick up and store the single required argument.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] Csci 4547 / 6647 program 4b: getopt_long()[SOLVED] Csci 4547 / 6647 program 4b: getopt_long()
$25