Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/share/doc/autogen/autogen.html/ drwxr-xr-x | |
| Viewing file: Select action/file-type: Previous: environrc, Up: Presetting Options [Contents][Index] 7.10.5 Config file only exampleIf for some reason it is difficult or unworkable to integrate configuration
file processing with command line option parsing, the #include <config.h>
#include <sys/types.h>
#include <stdio.h>
#include <pwd.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <autoopts/options.h>
int main(int argc, char ** argv) {
char const * greeting = "Hello";
char const * greeted = "World";
tOptionValue const * pOV = configFileLoad("hello.conf");
if (pOV != NULL) {
const tOptionValue* pGetV = optionGetValue(pOV, "greeting");
if ( (pGetV != NULL)
&& (pGetV->valType == OPARG_TYPE_STRING))
greeting = strdup(pGetV->v.strVal);
pGetV = optionGetValue(pOV, "personalize");
if (pGetV != NULL) {
struct passwd * pwe = getpwuid(getuid());
if (pwe != NULL)
greeted = strdup(pwe->pw_gecos);
}
optionUnloadNested(pOV); /* deallocate config data */
}
printf("%s, %s!\n", greeting, greeted);
return 0;
}
With that text in a file named “hello.c”, this short script: cc -o hello hello.c `autoopts-config cflags ldflags` ./hello echo 'greeting Buzz off' > hello.conf ./hello echo personalize > hello.conf ./hello will produce the following output: Hello, World! Buzz off, World! Hello, Bruce Korb,,,! |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0047 ]-- |