args.cc File Reference

Commandline arguments utility functions. More...

#include "args.h"
#include <qmap.h>
#include <qstring.h>
#include "qtcompat.h"
#include "util.h"
#include "version.h"
#include <assert.h>
#include <iostream>
#include <qobject.h>
#include <QLIST>
#include <qstringlist.h>
#include <stdlib.h>

Typedefs

typedef QMap< QString, optHandlerOptionMap
typedef QMap< QString,
optHandlerParam
OptionMapParam
typedef QMap< QString, QString > OptionHelp

Functions

int handleOption (const QString &param)
const QString nextParam (const QString &param)
void printHeader ()
void printHeaderErr ()
void handleHelpOptions ()
void handleStopOpt ()
void optionHandler (const QString &param, optHandler h, const QString &help)
void optionHandlerParam (const QString &param, const QString &paramName, optHandlerParam h, const QString &help)
void setArgv0 (const QString &name)
QStringList handleParams (int _argc, char **_argv)

Variables

bool stopOpt = false
QString binName
OptionHelp optHelp
OptionHelp optParamName
OptionMap optMap
OptionMapParam optMapParam
int argIndex
int argc
char ** argv
int maxParamNameLen = 1

Detailed Description

Commandline arguments utility functions.

Utility functions to work with commandline arguments

Author:
Martin Petricek

Typedef Documentation

typedef QMap<QString, QString> OptionHelp

Option help map

typedef QMap<QString, optHandler> OptionMap

Option handler map

typedef QMap<QString, optHandlerParam> OptionMapParam

Option handler map (with parameter)


Function Documentation

void handleHelpOptions (  ) 

Standard handler to handle --help parameter Prints all registered commandline options along with their helptext to STDOUT and exits

References util::CON, util::convertFromUnicode(), maxParamNameLen, gui::opt, optHelp, and optParamName.

Referenced by handleHelp().

int handleOption ( const QString &  param  ) 

Calls option handler on given option

Parameters:
param Commandline option to check
Returns:
0 if option is valid, but without parameters, 1 if option 'consumed' parameter after it, -1 if option is invalid

References nextParam(), optMap, and optMapParam.

Referenced by handleParams().

QStringList handleParams ( int  _argc,
char **  _argv 
)

Function to handle commandline parameters using installed callbacks Will terminate program with error message if unknown or invalid commandline options are found

Parameters:
_argc count of parameters (standard argc)
_argv parameters (standard argv)
Returns:
List of non-option parameters;

References argc, argIndex, argv, binName, util::fatalError(), handleOption(), printHeaderErr(), setArgv0(), and stopOpt.

Referenced by main().

void handleStopOpt (  ) 

handle -- parameter (stop processing option)

References stopOpt.

Referenced by main().

const QString nextParam ( const QString &  param  ) 

Get next parameter from commandline

Parameters:
param name of currently processed parameter

References argc, argIndex, argv, binName, util::fatalError(), and printHeaderErr().

Referenced by handleOption().

void optionHandler ( const QString &  param,
optHandler  h,
const QString &  help 
)

Register function to handle option without parameter

Parameters:
param Name of option (case sensitive)
h Function to handle this option
help Brief one-line help about this option

References maxParamNameLen, optHelp, and optMap.

Referenced by main().

void optionHandlerParam ( const QString &  param,
const QString &  paramName,
optHandlerParam  h,
const QString &  help 
)

Register function to handle option with parameter Parameters can be accepted as: -opt[n], -opt [n]

Parameters:
param Name of option (case sensitive)
paramName Name of parameter (only shown in help)
h Function to handle this option
help Brief one-line help about this option

References maxParamNameLen, optHelp, optMapParam, and optParamName.

Referenced by main().

void printHeader (  ) 

Print out application header (name and version) to stdout

References APP_NAME, and PDFEDIT_VERSION.

Referenced by handleHelp().

void printHeaderErr (  ) 

Print out application header (name and version) to stderr

References APP_NAME, and PDFEDIT_VERSION.

Referenced by handleParams(), main(), and nextParam().

void setArgv0 ( const QString &  name  ) 

Sets name of binary to show in help, etc ... (parameter should be argv[0])

Parameters:
name name of binary

References binName.

Referenced by handleParams().


Variable Documentation

int argc

Standard argc

Referenced by handleParams(), and nextParam().

int argIndex

Argument index currently processed

Referenced by handleParams(), and nextParam().

char** argv

Standard argv

Referenced by handleParams(), and nextParam().

QString binName

Name of the program (argv[0])

Referenced by handleHelp(), handleParams(), nextParam(), and setArgv0().

int maxParamNameLen = 1

Length of longest parameter name (including name of its argument)

Referenced by handleHelpOptions(), optionHandler(), and optionHandlerParam().

Option help texts

Referenced by handleHelpOptions(), optionHandler(), and optionHandlerParam().

Option handlers (without parameters)

Referenced by handleOption(), and optionHandler().

Option handlers (with parameters)

Referenced by handleOption(), and optionHandlerParam().

Option parameter names

Referenced by handleHelpOptions(), and optionHandlerParam().

bool stopOpt = false

Stop processing options from commandline?

Referenced by handleParams(), and handleStopOpt().