NASA Logo
Ocean Color Science Software

ocssw V2022
argpar.c File Reference
#include "argpar.h"
#include "shash.h"
#include <ctype.h>
#include <errno.h>
#include <libgen.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for argpar.c:

Go to the source code of this file.

Classes

struct  parser
 
struct  parser_chain
 
struct  parser_counts
 

Macros

#define ARGPAR_IMPLEMENTATION   2001001
 
#define ARGPAR_IMPLEMENTATION_STR   "2.1.1"
 
#define ARGPAR_API_VERSION   2001000
 
#define ARGPAR_API_VERSION_STR   "2.1.0"
 

Functions

int compare_strings (const void *a, const void *b)
 
int argpar_clean (argpar *p)
 
int argpar_parse_args (argpar *p, unsigned argc, char *argv[], unsigned flags, unsigned *end_index, void *input)
 
int argpar_parse_file (argpar *p, const char *path, unsigned flags, void *input)
 
const char * argpar_version ()
 
char ** argpar_split_str (char *str, const char *delim)
 
char ** argpar_split_trim (char *str, const char *delim)
 
int * argpar_split_int (char *str, const char *delim)
 
double * argpar_split_dbl (char *str, const char *delim)
 

Variables

const char * argpar_program_name
 
FILE * argpar_ostream
 
const char * argpar_program_version
 
void(* argpar_program_version_hook )(FILE *stream, argpar_state *state)
 

Macro Definition Documentation

◆ ARGPAR_API_VERSION

#define ARGPAR_API_VERSION   2001000

Definition at line 4 of file argpar.c.

◆ ARGPAR_API_VERSION_STR

#define ARGPAR_API_VERSION_STR   "2.1.0"

Definition at line 5 of file argpar.c.

◆ ARGPAR_IMPLEMENTATION

#define ARGPAR_IMPLEMENTATION   2001001

Definition at line 2 of file argpar.c.

◆ ARGPAR_IMPLEMENTATION_STR

#define ARGPAR_IMPLEMENTATION_STR   "2.1.1"

Definition at line 3 of file argpar.c.

Function Documentation

◆ argpar_clean()

int argpar_clean ( argpar p)

Free any space consumed by argpar for parfiles.

Parameters
[in]pargpar structure to clean up.
Returns
0 on success.

Definition at line 656 of file argpar.c.

◆ argpar_parse_args()

int argpar_parse_args ( argpar p,
unsigned  argc,
char *  argv[],
unsigned  flags,
unsigned *  end_index,
void *  input 
)

Parse an array of key=value pairs and/or key arguments.

Parameters
[in]pargpar object to use to parse file
[in]argcNumber of arguments to parse.
[in]argvArray of key=value pairs and/or key arguments, starting at index 1. The first element is assumed to be the calling program's name.
[in]flagsFlags to modify the behavior of the parser.
[out]end_indexSet to the last index parsed.
[in]inputPointer to pass to the configured parser callback.
Returns
0 when the parsing is completed or the return value of the callback function if it bailed out early.
See also
ARGPAR_CAST_ARGS

Definition at line 686 of file argpar.c.

◆ argpar_parse_file()

int argpar_parse_file ( argpar p,
const char *  path,
unsigned  flags,
void *  input 
)

Parse a key=value store file.

Parameters
[in]pargpar object to use to parse file
[in]pathPath of file, absolute or relative to the current directory.
[in]flagsFlags to modify the behavior of the parser.
[in]inputPointer to pass to the configured parser callback.
Returns
0 when the parsing is completed or the return value of the callback function if it bailed out early.
See also
ARGPAR_CAST_ARGS

Definition at line 737 of file argpar.c.

◆ argpar_split_dbl()

double* argpar_split_dbl ( char *  str,
const char *  delim 
)

Splits a string on a delimiter, returning a NAN-terminated list of doubles.

Parameters
[in]strString on which to split. This string is modified, replacing delimiters with '\0'. Return pointers are points to within this string.
[in]delimDelimiters on which to split (each character is a separate delimiter).
Returns
NULL on failure, malloc'd array of doubles ending in NULL on success. Compare to INFINITY for empty strings. Conversion errors result in total failure (returning NULL). (N.B., the proper way to perform these comparisons are the macros isinf and isnan.)

Definition at line 816 of file argpar.c.

◆ argpar_split_int()

int* argpar_split_int ( char *  str,
const char *  delim 
)

Splits a string on a delimiter, returning a NULL_INT-terminated list of ints.

Parameters
[in]strString on which to split. This string is modified, replacing delimiters with '\0'. Return pointers are points to within this string.
[in]delimDelimiters on which to split (each character is a separate delimiter).
Returns
NULL on failure, malloc'd array of ints ending in NULL_INT on success. Compare to EMPTY_INT for empty strings. Conversion errors result in total failure (returning NULL).

Definition at line 792 of file argpar.c.

◆ argpar_split_str()

char** argpar_split_str ( char *  str,
const char *  delim 
)

Splits a string on a delimiter, returning a NULL-terminated list of strings.

Parameters
[in]strString on which to split. This string is modified, replacing delimiters with '\0'. Return pointers are points to within this string.
[in]delimDelimiters on which to split (each character is a separate delimiter).
Returns
NULL on failure, malloc'd array of strings ending in NULL on success.

Definition at line 751 of file argpar.c.

◆ argpar_split_trim()

char** argpar_split_trim ( char *  str,
const char *  delim 
)

Splits a string on a delimiter, returning a NULL-terminated list of strings, trimming left and right whitespace from each string.

Parameters
[in]strString on which to split. This string is modified, replacing delimiters with '\0'. Return pointers are points to within this string.
[in]delimDelimiters on which to split (each character is a separate delimiter).
Returns
NULL on failure, malloc'd array of strings ending in NULL on success.

Definition at line 776 of file argpar.c.

◆ argpar_version()

const char* argpar_version ( )

Returns the source code version and the implemented API version.

No assumptions are made about the format of the return value.

Definition at line 747 of file argpar.c.

◆ compare_strings()

int compare_strings ( const void *  a,
const void *  b 
)

Definition at line 113 of file argpar.c.

Variable Documentation

◆ argpar_ostream

FILE* argpar_ostream

Where to print errors and usage summaries to, defaults to STDERR.

Used as the stream for printing help and usage messages. Defaults to STDERR.

Definition at line 24 of file argpar.c.

◆ argpar_program_name

const char* argpar_program_name

How to display the program name. If not given, it will be derived during a call to argpar_parse_args.

Used as a default for the program's invocation name if one is not found.

Definition at line 21 of file argpar.c.

◆ argpar_program_version

const char* argpar_program_version

Used as the program version string. If set, a version=1 option is automatically added. argpar_program_version_hook takes precedence.

Definition at line 26 of file argpar.c.

◆ argpar_program_version_hook

void(* argpar_program_version_hook) (FILE *stream, argpar_state *state)

Called to print the version string. If set, a version=1 option is automatically added.

Definition at line 27 of file argpar.c.