Home
Highly Reusable Software By activity User Interface Text Strings Math Processing
Stored Data
Communications
Hard World File System
|
#License - #Source code - #Example Use -
#include <librock/target/types.c> #include <librock/exec.h> int librock_avscan(int argc, const char **argv, /* argument array */ const char *optKeys, /* blank separated list of accepted options */ const char **ppszOpt, /* Store pointer into optKeys of match*/ const char **ppszValue) /* Store pointer to option value, if any */
This replaces optarg(), with a better behaved function that does not use globals or static storage, or write error messages. librock_avscan is designed to be used in contexts other than command line argv[] processing.
optKeys defines the accepted options. It is a list of blank separated strings of one or more of the following forms:
-a -a= --long-name --long-name= where 'a' may be any single alphabetic character. "long-name" may contain any alpha-numeric character, and '_', and '-'. The suffix of '=' means that a value is always expected to be present. When the key is the short form '-a=', the value is taken to start at the character immediately following the 'a'. If there is no character following the 'a', the entire next argument in the argv input array is the value. If the character following 'a' is '=', the value is everything after the '='. When the key is the long form '--long-option', the value is taken to start after '=', if '=' is not present, the entire next argument in the argv array is the value. Typical use is #ifdef librock_TYPICAL_USE_avscan int testargc = 6; char *testargv[7] = { "testargv0", "-b", "-t=value", "--long-t", "-b", /* Argument to previous */ "-b=20", /* Not recognized. -b does not take a value */ 0 }; int iArg = 1; char *pszOpt; char *pszOptVal; while(iArg < testargc) { iArg += librock_avscan(testargc - iArg,&testargv[iArg],"-b -t= --long-t=",&pszOpt,&pszOptVal); if (!pszOpt) { /* Nothing matched on this one. Stop processing*/ break; } if (!librock_wordcmp(pszOpt,"-b")) { printf("Option: -b\n"); } if (!librock_wordcmp(pszOpt,"-t=")||!librock_wordcmp(pszOpt,"--long-t=")) { /* the testargv had one of the following -t=Optval --long-t=Optval -t Optval --long-t Optval -tOptval */ printf("Option: -t=%s\n",pszOptVal); } } #endif
strncmp() librock_countbl() librock_counttowh() librock_wordcmp()
Copyright 1998-2002 Forrest J. Cavalier III, http://www.mibsoftware.com Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in <librock/license/librock.txt> librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45
librock_avscan passed tests in tavscan (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_avscan passed tests in tavscan (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)
Want to help? We welcome comments, patches. -- Need help? Request paid support.