Go to the documentation of this file.
56 for (i = 0; i < a->
argc; ++i)
58 newargv[i] = a->
argv[i];
119 for (i = 0; i < a->
argc; ++i)
143 const size_t newargc = a->
argc + add + 1;
185 for (
size_t i = 0; i < headroom; ++i)
191 for (
size_t i = 0; i < source->
argc; ++i)
263 msg(msglev,
"%s: %s", prefix,
argv_str(a, &gc, 0));
296 bool in_token =
false;
297 char *
f =
gc_malloc(strlen(format) + 1,
true, gc);
298 for (
int i = 0, j = 0; i < strlen(format); i++)
300 if (format[i] ==
' ')
351 const char delim = 0x1D;
363 size_t argc = argres->
argc;
377 va_copy(tmplist, arglist);
378 int len = vsnprintf(NULL, 0,
f, tmplist);
389 size_t size = len + 1;
391 len = vsnprintf(buf, size,
f, arglist);
392 if (len < 0 || len >= size)
401 char *end = strchr(buf, delim);
407 end = strchr(buf, delim);
411 if (argres->
argc != argc)
443 va_start(arglist, format);
467 va_start(arglist, format);
493 for (i = 0; i < nparms; ++i)
static void argv_init(struct argv *a)
Initialise an already allocated struct argv.
static struct gc_arena gc_new(void)
static struct argv argv_clone(const struct argv *source, const size_t headroom)
Clones a struct argv with all the contents to a new allocated struct argv.
bool argv_printf_cat(struct argv *argres, const char *format,...)
printf() inspired argv concatenation.
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num, int msglevel, struct gc_arena *gc)
void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix)
Similar to argv_msg() but prefixes the messages being written with a given string.
void argv_parse_cmd(struct argv *argres, const char *cmdstr)
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot...
static void argv_grow(struct argv *a, const size_t add)
Extends an existing struct argv to carry minimum 'add' number of new arguments.
char * string_alloc(const char *str, struct gc_arena *gc)
static char * argv_prep_format(const char *format, const char delim, size_t *count, struct gc_arena *gc)
Prepares argv format string for further processing.
static bool argv_printf_arglist(struct argv *argres, const char *format, va_list arglist)
Create a struct argv based on a format string.
#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc)
static size_t adjust_power_of_2(size_t u)
struct argv argv_insert_head(const struct argv *a, const char *head)
Inserts an argument string in front of all other argument slots.
static void argv_extend(struct argv *a, const size_t newcap)
Resizes the list of arguments struct argv can carry.
const char * argv_str(const struct argv *a, struct gc_arena *gc, const unsigned int flags)
Generate a single string with all the arguments in a struct argv concatenated.
Garbage collection arena used to keep track of dynamically allocated memory.
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
static void gc_free(struct gc_arena *a)
static void argv_reset(struct argv *a)
Resets the struct argv to an initial state.
void argv_msg(const int msglev, const struct argv *a)
Write the arguments stored in a struct argv via the msg() command.
static void argv_append(struct argv *a, char *str)
Appends a string to to the list of arguments stored in a struct argv This will ensure the list size i...
char * print_argv(const char **p, struct gc_arena *gc, const unsigned int flags)