Scroll to navigation

VECARGS(3) Library Functions Manual VECARGS(3)

NAME

vecargs - command argument vector insertion routines

SYNOPSIS

#include <vecargs.h>

char** vecload(char* string); char** vecfile(const char* path); char** vecstring(const char* string); void vecfree(char**, int); int vecargs(char** vec, int* argcp, char*** argvp);

DESCRIPTION

vecload loads a string vector from lines in string. string may be modified upon return. Each line in string is treated as a new vector element. Lines with # as the first character are comments. \newline joins consecutive lines. A string vector pointer is returned, 0 on error.

vecfile constructs a string vector by calling vecload on the contents of the file named by path. The string vector pointer is returned, 0 on error.

vecstring constructs a string vector by calling vecload on a copy of string. The string vector pointer is returned, 0 on error.

vecfree frees a string vector allocated by vecfile, vecload or vecstring.

vecargs inserts the string vector vec (as returned by vecfile, vecload or vecstring) between (*argvp)[0] and (*argvp)[1], sliding (*argvp)[1] ... over. NULL and empty string args in vec are not copied. vecfree(vec) is called before the return. -1 is returned if the insertion failed.

EXAMPLES

vecargs is commonly used to modify command argv from fixed files. For example, make(1) checks for the files ./Makeargs and ./makeargs to modify its arguments on startup. Its a handy way to override default options on a directory by directory basis without modify the standard control files (Makefile in this case.)

CAVEATS

This paradigm is not recommended for all commands; only a few exceptions make sense.