gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Data Structures | Functions
carg.h File Reference

argument utilities More...

Go to the source code of this file.

Data Structures

struct  CArg
 structure used to parse arguments More...
 

Functions

ANN m_str option_argument (struct CArg *ca)
 returns the option to the argument, errors and returns if none
 
ANN Vector split_args (MemPool, const m_str str)
 returns separated arguments from a string in a vector.
 

Detailed Description

argument utilities

Definition in file carg.h.

Function Documentation

◆ option_argument()

ANN m_str option_argument ( struct CArg * ca)

returns the option to the argument, errors and returns if none

Definition at line 7 of file carg.c.

7 {
8 const char key = ca->argv[ca->idx][1];
9 const m_str str = (ca->argv[ca->idx][2] == '\0' ? ca->argv[++ca->idx]
10 : ca->argv[ca->idx] + 2);
11 if (!str) gw_err(_("option '-%c' needs arguments\n"), key);
12 return str;
13}
#define _(String)
Definition defs.h:13
#define gw_err(...)
similar to fprintf(stderr, fmt, ...)
Definition err_msg.h:11
char * m_str
Definition gwcommon.h:14
char ** str
Definition gwion_print.h:2
char ** argv
array of char* arguments
Definition carg.h:9
int idx
curr index [internal]
Definition carg.h:11

◆ split_args()

ANN Vector split_args ( MemPool p,
const m_str str )

returns separated arguments from a string in a vector.

each value is a mp_allocated string. freeing it is caller responsability.

Definition at line 45 of file carg.c.

45 {
46 struct ArgSplitter as = {.str = str, .v = new_vector(p) };
47 _split_args(p, &as);
48 return as.v;
49}
static ANN void _split_args(MemPool mp, struct ArgSplitter *as)
Definition carg.c:21
used internally to split arguments
Definition carg.c:16
m_str str
Definition carg.c:17
Vector v
Definition carg.c:18
Vector new_vector(MemPool p)
Definition vector.c:8