Blame carg_parser.h

Packit Bot a3ac83
/*  Arg_parser - POSIX/GNU command line argument parser. (C version)
Packit Bot a3ac83
    Copyright (C) 2006-2017 Antonio Diaz Diaz.
Packit Bot a3ac83
Packit Bot a3ac83
    This library is free software. Redistribution and use in source and
Packit Bot a3ac83
    binary forms, with or without modification, are permitted provided
Packit Bot a3ac83
    that the following conditions are met:
Packit Bot a3ac83
Packit Bot a3ac83
    1. Redistributions of source code must retain the above copyright
Packit Bot a3ac83
    notice, this list of conditions and the following disclaimer.
Packit Bot a3ac83
Packit Bot a3ac83
    2. Redistributions in binary form must reproduce the above copyright
Packit Bot a3ac83
    notice, this list of conditions and the following disclaimer in the
Packit Bot a3ac83
    documentation and/or other materials provided with the distribution.
Packit Bot a3ac83
Packit Bot a3ac83
    This library is distributed in the hope that it will be useful,
Packit Bot a3ac83
    but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot a3ac83
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit Bot a3ac83
*/
Packit Bot a3ac83
Packit Bot a3ac83
/*  Arg_parser reads the arguments in 'argv' and creates a number of
Packit Bot a3ac83
    option codes, option arguments and non-option arguments.
Packit Bot a3ac83
Packit Bot a3ac83
    In case of error, 'ap_error' returns a non-null pointer to an error
Packit Bot a3ac83
    message.
Packit Bot a3ac83
Packit Bot a3ac83
    'options' is an array of 'struct ap_Option' terminated by an element
Packit Bot a3ac83
    containing a code which is zero. A null name means a short-only
Packit Bot a3ac83
    option. A code value outside the unsigned char range means a
Packit Bot a3ac83
    long-only option.
Packit Bot a3ac83
Packit Bot a3ac83
    Arg_parser normally makes it appear as if all the option arguments
Packit Bot a3ac83
    were specified before all the non-option arguments for the purposes
Packit Bot a3ac83
    of parsing, even if the user of your program intermixed option and
Packit Bot a3ac83
    non-option arguments. If you want the arguments in the exact order
Packit Bot a3ac83
    the user typed them, call 'ap_init' with 'in_order' = true.
Packit Bot a3ac83
Packit Bot a3ac83
    The argument '--' terminates all options; any following arguments are
Packit Bot a3ac83
    treated as non-option arguments, even if they begin with a hyphen.
Packit Bot a3ac83
Packit Bot a3ac83
    The syntax for optional option arguments is '-<short_option><argument>'
Packit Bot a3ac83
    (without whitespace), or '--<long_option>=<argument>'.
Packit Bot a3ac83
*/
Packit Bot a3ac83
Packit Bot a3ac83
#ifdef __cplusplus
Packit Bot a3ac83
extern "C" {
Packit Bot a3ac83
#endif
Packit Bot a3ac83
Packit Bot a3ac83
enum ap_Has_arg { ap_no, ap_yes, ap_maybe };
Packit Bot a3ac83
Packit Bot a3ac83
struct ap_Option
Packit Bot a3ac83
  {
Packit Bot a3ac83
  int code;			/* Short option letter or code ( code != 0 ) */
Packit Bot a3ac83
  const char * name;		/* Long option name (maybe null) */
Packit Bot a3ac83
  enum ap_Has_arg has_arg;
Packit Bot a3ac83
  };
Packit Bot a3ac83
Packit Bot a3ac83
Packit Bot a3ac83
struct ap_Record
Packit Bot a3ac83
  {
Packit Bot a3ac83
  int code;
Packit Bot a3ac83
  char * argument;
Packit Bot a3ac83
  };
Packit Bot a3ac83
Packit Bot a3ac83
Packit Bot a3ac83
struct Arg_parser
Packit Bot a3ac83
  {
Packit Bot a3ac83
  struct ap_Record * data;
Packit Bot a3ac83
  char * error;
Packit Bot a3ac83
  int data_size;
Packit Bot a3ac83
  int error_size;
Packit Bot a3ac83
  };
Packit Bot a3ac83
Packit Bot a3ac83
Packit Bot a3ac83
char ap_init( struct Arg_parser * const ap,
Packit Bot a3ac83
              const int argc, const char * const argv[],
Packit Bot a3ac83
              const struct ap_Option options[], const char in_order );
Packit Bot a3ac83
Packit Bot a3ac83
void ap_free( struct Arg_parser * const ap );
Packit Bot a3ac83
Packit Bot a3ac83
const char * ap_error( const struct Arg_parser * const ap );
Packit Bot a3ac83
Packit Bot a3ac83
    /* The number of arguments parsed (may be different from argc) */
Packit Bot a3ac83
int ap_arguments( const struct Arg_parser * const ap );
Packit Bot a3ac83
Packit Bot a3ac83
    /* If ap_code( i ) is 0, ap_argument( i ) is a non-option.
Packit Bot a3ac83
       Else ap_argument( i ) is the option's argument (or empty). */
Packit Bot a3ac83
int ap_code( const struct Arg_parser * const ap, const int i );
Packit Bot a3ac83
Packit Bot a3ac83
const char * ap_argument( const struct Arg_parser * const ap, const int i );
Packit Bot a3ac83
Packit Bot a3ac83
#ifdef __cplusplus
Packit Bot a3ac83
}
Packit Bot a3ac83
#endif