nis-util  1.0.D108
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
arglex Class Reference

#include <arglex.h>

Inheritance diagram for arglex:
arglex_afpvol arglex_auto_master arglex_ethers arglex_group arglex_group_members arglex_hosts arglex_netgroup arglex_netid arglex_netmasks arglex_networks arglex_passwd arglex_protocols arglex_services

Data Structures

struct  table_t

Public Types

enum  {
  token_configuration_file, token_eoln, token_group_name_maximum, token_help,
  token_license, token_number, token_option, token_page_length,
  token_page_width, token_passwd_name_maximum, token_stdio, token_string,
  token_tracing, token_verbose, token_verbose_not, token_version,
  token_warning, token_warning_not, token_MAX
}

Public Member Functions

virtual ~arglex ()
 arglex (int argc, char **argv)
int token_first (void)
int token_next (void)
int token_cur (void) const
rcstring get_string_value (void) const
long get_integer_value (void) const
const source_locationget_source_location (void) const
const char * token_name (int num) const
void usage (void) const
void bad_argument (void) const
void generic_argument (void)
void check_stdin_references (void)
void check_stdout_references (void)
rcstring get_filename_or_stdin (void)
void get_filename_or_stdin (rcstring &fnvar)
rcstring get_filename_or_stdout (void)
void get_filename_or_stdout (rcstring &fnvar)

Static Public Member Functions

static bool compare (const char *formal, const char *actual)

Protected Member Functions

void table_set (const table_t *tp)
void usage_tail_set (const char *text)

Private Types

typedef std::list
< arglex_source::pointer
sources_t
typedef std::list< const
table_t * > 
tables_t

Private Member Functions

void help (const char *name=0) const
void version (void) const
void license (void) const
const char * usage_tail_get (void) const
void push_arg_back (const char *text)
 arglex ()
 arglex (const arglex &rhs)
arglexoperator= (const arglex &rhs)

Private Attributes

sources_t sources
int token
source_location token_locn
rcstring value_string
long value_number
tables_t tables
const char * usage_tail_
int number_of_stdin_references
int number_of_stdout_references

Detailed Description

The arglex class is used to represent the current parse state of the command line, and perform lexical analysis on each command line argument.

Definition at line 33 of file arglex.h.


Member Typedef Documentation

typedef std::list<arglex_source::pointer> arglex::sources_t [private]

Definition at line 274 of file arglex.h.

typedef std::list<const table_t *> arglex::tables_t [private]

Definition at line 321 of file arglex.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
token_configuration_file 
token_eoln 
token_group_name_maximum 
token_help 
token_license 
token_number 
token_option 
token_page_length 
token_page_width 
token_passwd_name_maximum 
token_stdio 
token_string 
token_tracing 
token_verbose 
token_verbose_not 
token_version 
token_warning 
token_warning_not 
token_MAX 

Definition at line 53 of file arglex.h.


Constructor & Destructor Documentation

arglex::~arglex ( ) [virtual]

The destructor.

Definition at line 35 of file arglex.cc.

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

The constructor.

Parameters:
argcThe number of command line arguments, including the command name as the first argument.
argvThe command line arguments, as an array of pointers to C strings, including the command name as the first argument.

Definition at line 40 of file arglex.cc.

arglex::arglex ( ) [private]

The default constructor. Do not use.

arglex::arglex ( const arglex rhs) [private]

The copy constructor. Do not use.

Parameters:
rhsThe right hand side of the initialisation.

Member Function Documentation

void arglex::bad_argument ( void  ) const

The bad_argument method is used to complain about an unknown or misplaced command line argument.

Note:
This method does not return.

Definition at line 451 of file arglex.cc.

The check_stdin_references method is used to check that stdin is only referenced once on the command line. It should be called when parsing command line options, whenever stdin is used as a file name.

Definition at line 565 of file arglex.cc.

The check_stdout_references method is used to check that stdout is only referenced once on the command line. It should be called when parsing command line options, whenever stdout is used as a file name.

Definition at line 634 of file arglex.cc.

bool arglex::compare ( const char *  formal,
const char *  actual 
) [static]

The compare class method is used to compare an argument name pattern with an actual argument.

Parameters:
formalThe argument name pattern. Upper case letters are mandatory, lower case letters are optional.
actualThe string to be checked.
Returns:
true if matches, false if not.

Definition at line 83 of file arglex.cc.

void arglex::generic_argument ( void  )

The generic_argument method is used to process all command line arguments not specific to any particular command. Usually this will result in a terminal error message.

Definition at line 26 of file generic_argument.cc.

The get_filename_or_stdin method is used to fetch the next token, and make sure it it either a string or "-" meaning stdin. If stdin, the reference count is checked, to prevent too many uses of stdin.

Definition at line 580 of file arglex.cc.

The get_filename_or_stdin is used to fetch the next command lien argument, as required for the option. If the variable isn't empty, a suitable duplicate option error message will be issued.

Definition at line 617 of file arglex.cc.

The get_filename_or_stdout method is used to fetch the next token, and make sure it it either a string or "-" meaning stdout. If stdout, the reference count is checked, to prevent too many uses of stdout.

Definition at line 649 of file arglex.cc.

The get_filename_or_stdin is used to fetch the next command line argument, as required for the option. If the variable isn't empty, a suitable duplicate option error message will be issued.

Definition at line 686 of file arglex.cc.

long arglex::get_integer_value ( void  ) const [inline]

The get_integer_value method is used to obtain the numeric value of the current token. If the current token is not a number, the result is undefined.

Definition at line 120 of file arglex.h.

const source_location & arglex::get_source_location ( void  ) const

The get_source_location method is used to obtain the source location of the most recent token returned by the token_next method. Usually this will be the command line, but not always.

Definition at line 703 of file arglex.cc.

rcstring arglex::get_string_value ( void  ) const [inline]

The get_string_value method is used to obtain the string value of the current token.

Note:
The value is undefined if token_next has not been called.

Definition at line 113 of file arglex.h.

void arglex::help ( const char *  name = 0) const [private]

The help method is called from the token_first method to print the help message (man page) of the command.

Definition at line 409 of file arglex.cc.

void arglex::license ( void  ) const [private]

The license method is called from the token_first method to print the license message of the command.

Definition at line 443 of file arglex.cc.

arglex& arglex::operator= ( const arglex rhs) [private]

The assignment operator. Do not use.

Parameters:
rhsThe right hand side of the assignment.
void arglex::push_arg_back ( const char *  text) [private]

The push_arg_back method is used to "return" a string to the input source. It uses token_locn for its location.

Parameters:
textThe text of the argument to be "returned" to the input.

Definition at line 193 of file arglex.cc.

void arglex::table_set ( const table_t tp) [protected]

The table_set method may be used by derived classes to add another set of option patterns and values. This is used to specialize the command line processing for individual programs.

This is usually called from within a derived class's constructor.

Parameters:
tpPointer to array of comamnd line options, terminated by an entry with a NULL name pointer. Use ARGLEX_END_MARKER as the last row of your table.

Definition at line 74 of file arglex.cc.

int arglex::token_cur ( void  ) const [inline]

The token_cur method is used to obtain the token number of the current token. It does not advance to the next token.

Definition at line 104 of file arglex.h.

int arglex::token_first ( void  )

The token_first method is called to obtain the first argument from the command line. It automatically processed the --help and --version options, and does not return if it sees them. It calls the token_next method to obtain the first token.

Returns:
The first token from the command line (not including the command name).

Definition at line 506 of file arglex.cc.

const char * arglex::token_name ( int  num) const

The token_name method is used to obtain the name of a token, given its number. This can be useful in error messages.

Parameters:
numThe token number.
Returns:
The token name.

Definition at line 368 of file arglex.cc.

int arglex::token_next ( void  )

The token_next methpod is used to advance to the next token from the command line. Usually this will be the next argument, but in the case of --name=value style options, this will be represented as two separate tokens.

Returns:
The next token from the command line (not including the command name).

Definition at line 200 of file arglex.cc.

void arglex::usage ( void  ) const

The usage method is used to print the usage message for the program, when a command line parse error occurs.

Note:
This method does not return.

Definition at line 551 of file arglex.cc.

const char * arglex::usage_tail_get ( void  ) const [private]

The usage_tail_get method is used to get the command's usage message's tail. Will never return a NULLO pointer, even if the usage tail has yet to be set.

Definition at line 543 of file arglex.cc.

void arglex::usage_tail_set ( const char *  text) [protected]

The usage_tail_set method is used to set the trailing portion of a command line usage methd. The default is empty, meaning the commands only accept options, and do not accept trailing file names.

This method is usually called from within a derived class's constructor.

Definition at line 536 of file arglex.cc.

void arglex::version ( void  ) const [private]

The version method is called from the token_first method to print the version message of the command.

Definition at line 422 of file arglex.cc.


Field Documentation

The number_of_stdin_references instance variable is used to remember how many times the standard input has been mentioned on the command line. This is used to emit appropriate error messages, when necessary.

Definition at line 351 of file arglex.h.

The number_of_stdout_references instance variable is used to remember how many times the standard output has been mentioned on the command line. This is used to emit appropriate error messages, when necessary.

Definition at line 359 of file arglex.h.

The sources instance variable is used to remember the push-down stack of command line argument sources. This is so that we can cope with "@filename" arguments.

Definition at line 281 of file arglex.h.

The tables instance variable is used to remember the set of arguments tables, one per derived class. This is appended to using the table_set method

Definition at line 328 of file arglex.h.

int arglex::token [private]

The token instance variable is used to remember the token number of the current token. This instance variable is maintained by the token_next method.

Note:
The value is undefined if token_next has not been called.

Definition at line 291 of file arglex.h.

The token_locn instance variable is used to remember the source (file) location of the most recent token, as returned by the token_next method.

Definition at line 298 of file arglex.h.

const char* arglex::usage_tail_ [private]

The usage_tail_ instance variable is used to remember the right hand end of the command's usage method. This is set using the usage_tail_set method, and obtained using the usage_tail_get method.

Definition at line 336 of file arglex.h.

long arglex::value_number [private]

The value_number instance variable is used to remember the value of the current token, if that token is a number. This instance variable is maintained by the token_next method.

Note:
The value is undefined if token_next has not been called, or if the current token is not a number.

Definition at line 319 of file arglex.h.

The value_string instance variable is used to remember the text of the current token. This instance variable is maintained by the token_next method.

Note:
The value is undefined if token_next has not been called.

Definition at line 308 of file arglex.h.


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