Skip to content

Commit

Permalink
Recognise -v and -q command line options
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbclements committed Apr 15, 2004
1 parent 7e9f5ec commit 81bfc83
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
57 changes: 57 additions & 0 deletions commandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ CommandLine::ExtraFile::ExtraFile(const string &name, u64 size)
CommandLine::CommandLine(void)
: operation(opNone)
, version(verUnknown)
, noiselevel(nlUnknown)
, blockcount(0)
, blocksize(0)
, firstblock(0)
Expand Down Expand Up @@ -98,6 +99,8 @@ void CommandLine::usage(void)
" -l : Limit size of recovery files (Don't use both -u and -l)\n"
" -n<n> : Number of recovery files (Don't use both -n and -l)\n"
" -m<n> : Memory (in MB) to use\n"
" -v [-v]: Be more verbose\n"
" -q [-q]: Be more quiet (-q -q gives silence)\n"
" -- : Treat all remaining CommandLine as filenames\n"
"\n"
"If you wish to create par2 files for a single source file, you may leave\n"
Expand Down Expand Up @@ -468,6 +471,54 @@ bool CommandLine::Parse(int argc, char *argv[])
}
break;

case 'v':
{
switch (noiselevel)
{
case nlUnknown:
{
if (argv[0][2] == 'v')
noiselevel = nlDebug;
else
noiselevel = nlNoisy;
}
break;
case nlNoisy:
case nlDebug:
noiselevel = nlDebug;
break;
default:
cerr << "Cannot use both -v and -q." << endl;
return false;
break;
}
}
break;

case 'q':
{
switch (noiselevel)
{
case nlUnknown:
{
if (argv[0][2] == 'q')
noiselevel = nlSilent;
else
noiselevel = nlQuiet;
}
break;
case nlQuiet:
case nlSilent:
noiselevel = nlSilent;
break;
default:
cerr << "Cannot use both -v and -q." << endl;
return false;
break;
}
}
break;

case '-':
{
argc--;
Expand Down Expand Up @@ -633,6 +684,12 @@ bool CommandLine::Parse(int argc, char *argv[])
return false;
}

// Default noise level
if (noiselevel == nlUnknown)
{
noiselevel = nlNormal;
}

// If we a creating, check the other parameters
if (operation == opCreate)
{
Expand Down
13 changes: 13 additions & 0 deletions commandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ class CommandLine
scUniform // All PAR2 files the same size
} Scheme;

typedef enum
{
nlUnknown = 0,
nlSilent, // Absolutely no output (other than errors)
nlQuiet, // Bare minimum of output
nlNormal, // Normal level of output
nlNoisy, // Lots of output
nlDebug // Extra debugging information
} NoiseLevel;

// Any extra files listed on the command line
class ExtraFile
{
Expand Down Expand Up @@ -92,6 +102,7 @@ class CommandLine
size_t GetMemoryLimit(void) const {return memorylimit;}
u64 GetLargestSourceSize(void) const {return largestsourcesize;}
u64 GetTotalSourceSize(void) const {return totalsourcesize;}
CommandLine::NoiseLevel GetNoiseLevel(void) const {return noiselevel;}

string GetParFilename(void) const {return parfilename;}
const list<CommandLine::ExtraFile>& GetExtraFiles(void) const {return extrafiles;}
Expand All @@ -100,6 +111,8 @@ class CommandLine
Operation operation; // The operation to be carried out.
Version version; // What version files will be processed.

NoiseLevel noiselevel; // How much display output should there be.

u32 blockcount; // How many blocks the source files should
// be virtually split into.

Expand Down

0 comments on commit 81bfc83

Please sign in to comment.