srecord  1.65.0
srecord::arglex Class Reference

The arglex class is used to implement a lexical analizer for command line arguments. More...

#include <arglex.h>

Inheritance diagram for srecord::arglex:

Classes

struct  table_ty
 The table_ty struct is used to repesent a row of a commandline option table, used to match option names with their corresponding tokens. More...
 
struct  value_ty
 The value_ty struct is used to represent the value of a command line argument. More...
 

Public Types

enum  {
  token_eoln , token_help , token_license , token_number ,
  token_option , token_page_width , token_page_length , token_stdio ,
  token_string , token_tracing , token_verbose , token_version ,
  token_MAX
}
 The "normal" command line tokens common to all programs. More...
 

Public Member Functions

virtual ~arglex ()
 The destructor. More...
 
void fatal_error (const char *fmt,...) FORMAT_PRINTF(2
 The fatal_error method may be used to print a fatal error message, and then exit via the usage() method. More...
 
void test_ambiguous (void) const
 The test_ambiguous method is for debugging. More...
 
 arglex ()
 The default constructor. More...
 
 arglex (arglex &)
 The copy constructor. More...
 
 arglex (int argc, char **argv)
 The normal constructor. More...
 
int token_cur () const
 The token_cur method is used to get the type of the current token. More...
 
int token_next (void)
 The token_next method is used to advance to the next command line option and determine what type of token it is. More...
 
int token_first (void)
 The token_first method is used to fetch the fisrt command like token (rather than use the token_next method). More...
 
const std::string & value_string () const
 The value_string method is used to get the string value of the current token. More...
 
long value_number () const
 The value_number method is used to get the numeric value of the current token. More...
 
const char * token_name (int tok) const
 The token_name method is used to turn a token type number into an equivalent string. More...
 
const char * token_name () const
 The token_name method is used to obtain the name of the current token. More...
 
void usage () const
 The usage method is used to print a usage summary. More...
 
void help (const char *=0) const
 The help method is used to print a help message. More...
 
void version () const
 The version method is used to print a version message. More...
 
void license () const
 The license method is used to print the license conditions of the program. More...
 
void bad_argument () const
 The bad_argument method is used to print an error message when the current token is inappropriate, then it calls usage, which exits. More...
 
void usage_tail_set (const char *)
 The usage_tail_set method is used to set the end of the command line to be printed as part of the usage method. More...
 
virtual void default_command_line_processing (void)
 The default_command_line_processing method is used to process command line arguments not handled by the derived class. More...
 

Static Public Member Functions

void static bool compare (const char *formal, const char *actual)
 The compare class method is used to compare a command line string with a formal spec of the option, to see if they compare equal. More...
 
static std::string abbreviate (const char *text)
 The abbreviate class method is used to take an option's long name, and turn it into the minimum possible string for that option. More...
 

Protected Member Functions

void table_set (const table_ty *)
 The table_set method is used to append more command line token tables to the list of tables to be scanned. More...
 
void deprecated_option (const std::string &formal_name)
 The deprecated_option method is used to nominate option patterns that are deprected. More...
 

Detailed Description

The arglex class is used to implement a lexical analizer for command line arguments.

Each comamnd line argument is analized to determine if it is a number, a string (file name) or an option.

Definition at line 38 of file arglex.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

The "normal" command line tokens common to all programs.

Enumerator
token_eoln 
token_help 
token_license 
token_number 
token_option 
token_page_width 
token_page_length 
token_stdio 
token_string 
token_tracing 
token_verbose 
token_version 
token_MAX 

Definition at line 49 of file arglex.h.

Constructor & Destructor Documentation

◆ ~arglex()

virtual srecord::arglex::~arglex ( )
virtual

The destructor.

◆ arglex() [1/3]

srecord::arglex::arglex ( )

The default constructor.

◆ arglex() [2/3]

srecord::arglex::arglex ( arglex )

The copy constructor.

◆ arglex() [3/3]

srecord::arglex::arglex ( int  argc,
char **  argv 
)

The normal constructor.

The argv and argv should be those passed to main(). Not manipulation is required.

Member Function Documentation

◆ fatal_error()

void srecord::arglex::fatal_error ( const char *  fmt,
  ... 
)

The fatal_error method may be used to print a fatal error message, and then exit via the usage() method.

Parameters
fmtThe format of the string - it controls the rest of the arguments. See printf(3) for more information.
Note
This method never returns.

◆ compare()

void static bool srecord::arglex::compare ( const char *  formal,
const char *  actual 
)
static

The compare class method is used to compare a command line string with a formal spec of the option, to see if they compare equal.

The actual is case-insensitive. Uppercase in the formal means a mandatory character, while lower case means optional. Any number of consecutive optional characters may be supplied by actual, but none may be skipped, unless all are skipped to the next non-lower-case letter.

The underscore (_) is like a lower-case minus, it matches "", "-" and "_".

The "*" in a pattern matches everything to the end of the line, anything after the "*" is ignored. The rest of the line is pointed to by the "partial" variable as a side-effect (else it will be 0). This rather ugly feature is to support "-I./dir" type options.

A backslash in a pattern nominates an exact match required, case must matche excatly here. This rather ugly feature is to support "-I./dir" type options.

For example: "-project" and "-P" both match "-Project", as does "-proJ", but "-prj" does not.

For example: "-devDir" and "-d_d" both match "-Development_Directory", but "-dvlpmnt_drctry" does not.

For example: to match include path specifications, use a pattern such as "-\\I*", and the partial global variable will have the path in it on return.

◆ abbreviate()

static std::string srecord::arglex::abbreviate ( const char *  text)
static

The abbreviate class method is used to take an option's long name, and turn it into the minimum possible string for that option.

◆ test_ambiguous()

void srecord::arglex::test_ambiguous ( void  ) const

The test_ambiguous method is for debugging.

It verifies that all of the option names are unique.

◆ table_set()

void srecord::arglex::table_set ( const table_ty )
protected

The table_set method is used to append more command line token tables to the list of tables to be scanned.

Usually one per derived class.

◆ token_cur()

int srecord::arglex::token_cur ( ) const
inline

The token_cur method is used to get the type of the current token.

Definition at line 238 of file arglex.h.

Referenced by token_name().

◆ token_next()

int srecord::arglex::token_next ( void  )

The token_next method is used to advance to the next command line option and determine what type of token it is.

It returns the type of the token; this value may also be fetched using the token_cur method.

◆ token_first()

int srecord::arglex::token_first ( void  )

The token_first method is used to fetch the fisrt command like token (rather than use the token_next method).

This does standard "help" and "version" options.

◆ value_string()

const std::string& srecord::arglex::value_string ( ) const
inline

The value_string method is used to get the string value of the current token.

Definition at line 259 of file arglex.h.

◆ value_number()

long srecord::arglex::value_number ( ) const
inline

The value_number method is used to get the numeric value of the current token.

Definition at line 265 of file arglex.h.

◆ token_name() [1/2]

const char* srecord::arglex::token_name ( int  tok) const

The token_name method is used to turn a token type number into an equivalent string.

Useful for some error messages.

Parameters
tokThe ID of the token to be named.

◆ token_name() [2/2]

const char* srecord::arglex::token_name ( ) const
inline

The token_name method is used to obtain the name of the current token.

Definition at line 280 of file arglex.h.

References token_cur(), and token_name().

Referenced by token_name().

◆ usage()

void srecord::arglex::usage ( ) const

The usage method is used to print a usage summary.

This is a fatal error; this method does not return.

◆ help()

void srecord::arglex::help ( const char *  = 0) const

The help method is used to print a help message.

◆ version()

void srecord::arglex::version ( ) const

The version method is used to print a version message.

◆ license()

void srecord::arglex::license ( ) const

The license method is used to print the license conditions of the program.

◆ bad_argument()

void srecord::arglex::bad_argument ( ) const

The bad_argument method is used to print an error message when the current token is inappropriate, then it calls usage, which exits.

This method does not return.

◆ usage_tail_set()

void srecord::arglex::usage_tail_set ( const char *  )

The usage_tail_set method is used to set the end of the command line to be printed as part of the usage method.

◆ default_command_line_processing()

virtual void srecord::arglex::default_command_line_processing ( void  )
virtual

The default_command_line_processing method is used to process command line arguments not handled by the derived class.

Reimplemented in srecord::arglex_tool.

◆ deprecated_option()

void srecord::arglex::deprecated_option ( const std::string &  formal_name)
protected

The deprecated_option method is used to nominate option patterns that are deprected.

Parameters
formal_nameThe pattern that is deprected. Must be an entry in one of the tables, otherwise users are going to be VERY confused.

The documentation for this class was generated from the following file: