Logo Search packages:      
Sourcecode: t1utils version File versions  Download package


Go to the documentation of this file.
/* -*- related-file-name: "../../liblcdf/clp.c" -*- */
#ifndef LCDF_CLP_H
#define LCDF_CLP_H
#ifdef __cplusplus
extern "C" {

/* clp.h - Public interface to CLP.
 * This file is part of CLP, the command line parser package.
 * Copyright (c) 1997-2008 Eddie Kohler, ekohler@gmail.com
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, subject to the conditions
 * listed in the Click LICENSE file, which is available in full at
 * http://www.pdos.lcs.mit.edu/click/license.html. The conditions include: you
 * must preserve this copyright notice, and you cannot mention the copyright
 * holders in advertising related to the Software without their permission.
 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
 * notice is a summary of the Click LICENSE file; the license in that file is
 * legally binding. */

typedef struct Clp_Option Clp_Option;
typedef struct Clp_Parser Clp_Parser;
typedef struct Clp_ParserState Clp_ParserState;

/** @brief Option description.
 * CLP users declare arrays of Clp_Option structures to specify what options
 * should be parsed.
 * @sa Clp_NewParser, Clp_SetOptions */
00034 struct Clp_Option {
00035     const char *long_name;    /**< Name of long option, or NULL if the option
                             has no long name. */
00037     int short_name;           /**< Character defining short option, or 0 if
                             the option has no short name. */
00039     int option_id;            /**< User-specified ID defining option,
                             returned by Clp_Next. */
00041     int val_type;       /**< ID of option's value type, or 0 if option
                             takes no value. */
00043     int flags;                /**< Option parsing flags. */

/** @name Value types
 * These values describe the type of an option's argument and are used in
 * the Clp_Option val_type field.  For example, if an option took integers, its
 * Clp_Option structure would have val_type set to Clp_ValInt. */
00051 #define Clp_NoVal       0     /**< @brief Option takes no value. */
00052 #define Clp_ValString         1     /**< @brief Option value is an
                                   arbitrary string. */
00054 #define Clp_ValStringNotOption      2     /**< @brief Option value is a
                                   non-option string.

            See Clp_DisallowOptions. */
00058 #define Clp_ValBool           3     /**< @brief Option value is a

            Accepts "true", "false", "yes", "no", "1", and "0", or any
            prefixes thereof.  The match is case-insensitive. */
00063 #define Clp_ValInt            4     /**< @brief Option value is a
                                   signed int.

            Accepts an optional "+" or "-" sign, followed by one or more
            digits.  The digits may be include a "0x" or "0X" prefix, for
            a hexidecimal number, or a "0" prefix, for an octal number;
            otherwise it is decimal. */
00070 #define Clp_ValUnsigned       5     /**< @brief Option value is an
                                   unsigned int.

            Accepts an optional "+" sign, followed by one or more
            digits.  The digits may be include a "0x" or "0X" prefix, for
            a hexidecimal number, or a "0" prefix, for an octal number;
            otherwise it is decimal. */
00077 #define Clp_ValDouble         6     /**< @brief Option value is a
            Accepts a real number as defined by strtod(). */
00080 #define Clp_ValFirstUser      10    /**< @brief Value types >=
                                   Clp_ValFirstUser are available
                                   for user types. */

/** @name Option flags
 * These flags are used in the Clp_Option flags field. */
00088 #define Clp_Mandatory         (1<<0)      /**< @brief Option flag: value
                                   is mandatory.

            It is an error if the option has no value.  This is the
            default if an option has arg_type != 0 and the Clp_Optional
            flag is not provided. */
00094 #define Clp_Optional          (1<<1)      /**< @brief Option flag: value
                                   is optional. */
00096 #define Clp_Negate            (1<<2)      /**< @brief Option flag: option
                                   may be negated.

            --no-[long_name] will be accepted in argument lists. */
00100 #define Clp_OnlyNegated       (1<<3)      /**< @brief Option flag: option
                                   <em>must</em> be negated.

            --no-[long_name] will be accepted in argument lists, but
            --[long_name] will not.  This is the default if long_name
            begins with "no-". */
00106 #define Clp_PreferredMatch    (1<<4)      /**< @brief Option flag: prefer this
                                   option when matching.

            Prefixes of --[long_name] should map to this option, even if
            other options begin with --[long_name]. */

/** @name Option character types
 * These flags are used in to define character types in Clp_SetOptionChar(). */
/*    Clp_NotOption           0 */
00117 #define Clp_Short       (1<<0)      /**< @brief Option character begins
                                   a set of short options. */
00119 #define Clp_Long        (1<<1)      /**< @brief Option character begins
                                   a long option. */
00121 #define Clp_ShortNegated      (1<<2)      /**< @brief Option character begins
                                   a set of negated short options. */
00123 #define Clp_LongNegated       (1<<3)      /**< @brief Option character begins
                                   a negated long option. */
00125 #define Clp_LongImplicit      (1<<4)      /**< @brief Option character can begin
                                   a long option, and is part of that
                                   long option. */

00130 #define Clp_NotOption         0     /**< @brief Clp_Next value: argument
                                   was not an option. */
00132 #define Clp_Done        -1    /**< @brief Clp_Next value: there are
                                   no more arguments. */
00134 #define Clp_BadOption         -2    /**< @brief Clp_Next value: argument
                                   was an erroneous option. */
00136 #define Clp_Error       -3    /**< @brief Clp_Next value: internal
                                   CLP error. */

00139 #define Clp_ValSize           40    /**< @brief Minimum size of the
                                   Clp_Parser val.cs field. */
00141 #define Clp_ValIntSize        10    /**< @brief Minimum size of the
                                   Clp_Parser val.is field. */

/** @brief A value parsing function.
 * @param clp the parser
 * @param vstr the value to be parsed
 * @param complain if nonzero, report error messages via Clp_OptionError
 * @param user_data user data passed to Clp_AddType()
 * @return 1 if parsing succeeded, 0 otherwise
00152 typedef int (*Clp_ValParseFunc)(Clp_Parser *clp, const char *vstr,
                        int complain, void *user_data);

/** @brief A function for reporting option errors.
 * @param clp the parser
 * @param message error message
00159 typedef void (*Clp_ErrorHandler)(Clp_Parser *clp, const char *message);

/** @brief Command line parser.
 * A Clp_Parser object defines an instance of CLP, including allowed options,
 * value types, and current arguments.
 * @sa Clp_NewParser, Clp_SetOptions, Clp_SetArguments */
00167 struct Clp_Parser {
00168     int negated;        /**< Whether the last option was negated. */

00170     int have_val;       /**< Whether the last option had a value. */
00171     const char *vstr;         /**< The string value provided with the last
                             option. */

    union {
      int i;
      unsigned u;
      double d;
      const char *s;
      void *pv;
      int64_t i64;
      uint64_t u64;
      char cs[Clp_ValSize];
      unsigned char ucs[Clp_ValSize];
      int is[Clp_ValIntSize];
      unsigned us[Clp_ValIntSize];
    } val;              /**< The parsed value provided with the last
                             option. */

00191     void *user_data;          /**< Uninterpreted by CLP; users can set
                             arbitrarily. */

    struct Clp_Internal *internal;

/** @cond never */
#if __GNUC__ >= 4
# define CLP_SENTINEL         __attribute__((sentinel))
# define CLP_SENTINEL         /* nothing */
/** @endcond never */

/** @brief Create a new Clp_Parser. */
Clp_Parser *Clp_NewParser(int argc, const char * const *argv,
                    int nopt, const Clp_Option *opt);

/** @brief Destroy a Clp_Parser object. */
void Clp_DeleteParser(Clp_Parser *clp);

/** @brief Return @a clp's program name. */
const char *Clp_ProgramName(Clp_Parser *clp);

/** @brief Set @a clp's program name. */
const char *Clp_SetProgramName(Clp_Parser *clp, const char *name);

/** @brief Set @a clp's error handler function. */
Clp_ErrorHandler Clp_SetErrorHandler(Clp_Parser *clp, Clp_ErrorHandler errh);

/** @brief Set @a clp's UTF-8 mode. */
int Clp_SetUTF8(Clp_Parser *clp, int utf8);

/** @brief Set @a clp's treatment of character @a c. */
int Clp_SetOptionChar(Clp_Parser *clp, int c, int type);

/** @brief Set @a clp's option definitions. */
int Clp_SetOptions(Clp_Parser *clp, int nopt, const Clp_Option *opt);

/** @brief Set @a clp's arguments. */
void Clp_SetArguments(Clp_Parser *clp, int argc, const char * const *argv);

/** @brief Set whether @a clp is searching for options. */
int Clp_SetOptionProcessing(Clp_Parser *clp, int on);

00240 #define Clp_DisallowOptions   (1<<0)      /**< @brief Value type flag: value
                                   can't be an option string.

            See Clp_AddType(). */

/** @brief Define a new value type for @a clp. */
int Clp_AddType(Clp_Parser *clp, int val_type, int flags,
            Clp_ValParseFunc parser, void *user_data);

00250 #define Clp_AllowNumbers      (1<<0)      /**< @brief String list flag: allow
                                 explicit numbers.

            See Clp_AddStringListType() and Clp_AddStringListTypeVec(). */

/** @brief Define a new string list value type for @a clp. */
int Clp_AddStringListTypeVec(Clp_Parser *clp, int val_type, int flags,
                       int nstrs, const char * const *strs,
                       const int *vals);

/** @brief Define a new string list value type for @a clp. */
int Clp_AddStringListType(Clp_Parser *clp, int val_type, int flags, ...)

/** @brief Parse and return the next argument from @a clp. */
int Clp_Next(Clp_Parser *clp);

/** @brief Return the next argument from @a clp without option parsing. */
const char *Clp_Shift(Clp_Parser *clp, int allow_options);

/** @brief Create a new Clp_ParserState. */
Clp_ParserState *Clp_NewParserState(void);

/** @brief Destroy a Clp_ParserState object. */
void Clp_DeleteParserState(Clp_ParserState *state);

/** @brief Save @a clp's current state in @a state. */
void Clp_SaveParser(const Clp_Parser *clp, Clp_ParserState *state);

/** @brief Restore parser state from @a state into @a clp. */
void Clp_RestoreParser(Clp_Parser *clp, const Clp_ParserState *state);

/** @brief Report a parser error. */
int Clp_OptionError(Clp_Parser *clp, const char *format, ...);

/** @brief Extract the current option as a string. */
int Clp_CurOptionNameBuf(Clp_Parser *clp, char *buf, int len);

/** @brief Extract the current option as a string. */
const char *Clp_CurOptionName(Clp_Parser *clp);

#ifdef __cplusplus

Generated by  Doxygen 1.6.0   Back to index