X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-config.c;h=f4aed0550a4969b5257fe8396d009f46d9daa594;hb=3535d4cb73628c720da1bf74627ded2aec6f2ca1;hp=0bfd9d4c66048cbea1efe39828748d72b17c2055;hpb=7dfbf0230218f8bac9b37326421c24547d22bbd8;p=src%2Fapp-framework-binder.git diff --git a/src/afb-config.c b/src/afb-config.c index 0bfd9d4c..f4aed055 100644 --- a/src/afb-config.c +++ b/src/afb-config.c @@ -16,7 +16,6 @@ */ #define _GNU_SOURCE -#define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO #include #include @@ -34,8 +33,9 @@ #if !defined(BINDING_INSTALL_DIR) #error "you should define BINDING_INSTALL_DIR" #endif - -#define AFB_VERSION "0.6" +#if !defined(AFB_VERSION) +#error "you should define AFB_VERSION" +#endif // default #define DEFLT_CNTX_TIMEOUT 3600 // default Client Connection @@ -230,14 +230,16 @@ static struct enumdesc mode_desc[] = { +--------------------------------------------------------- */ static void printVersion(FILE * file) { - fprintf(file, "\n----------------------------------------- \n"); - fprintf(file, " AFB [Application Framework Binder] version=%s |\n", - AFB_VERSION); - fprintf(file, " \n"); - fprintf(file, - " Copyright (C) 2015, 2016, 2017 \"IoT.bzh\" [fulup -at- iot.bzh]\n"); - fprintf(file, " AFB comes with ABSOLUTELY NO WARRANTY.\n"); - fprintf(file, " Licence Apache 2\n\n"); + static const char version[] = + "\n" + " AFB [Application Framework Binder] version="AFB_VERSION"\n" + "\n" + " Copyright (C) 2015, 2016, 2017 \"IoT.bzh\"\n" + " AFB comes with ABSOLUTELY NO WARRANTY.\n" + " Licence Apache 2\n" + "\n"; + + fprintf(file, "%s", version); } /*---------------------------------------------------------- @@ -752,12 +754,47 @@ void afb_config_dump(struct afb_config *config) #undef NN } +static void on_environment_list(struct afb_config_list **to, const char *name) +{ + char *value = getenv(name); + + if (value) + list_add(to, value); +} + +static void on_environment_enum(int *to, const char *name, struct enumdesc *desc) +{ + char *value = getenv(name); + + if (value) { + while (desc->name) { + if (strcmp(desc->name, value)) + desc++; + else { + *to = desc->value; + return; + } + } + WARNING("Unknown value %s for environment variable %s, ignored", value, name); + } +} + +static void parse_environment(struct afb_config *config) +{ + on_environment_enum(&config->tracereq, "AFB_TRACEREQ", tracereq_desc); + on_environment_enum(&config->traceditf, "AFB_TRACEDITF", traceditf_desc); + on_environment_enum(&config->tracesvc, "AFB_TRACESVC", tracesvc_desc); + on_environment_enum(&config->traceevt, "AFB_TRACEEVT", traceevt_desc); + on_environment_list(&config->ldpaths, "AFB_LDPATHS"); +} + struct afb_config *afb_config_parse_arguments(int argc, char **argv) { struct afb_config *result; result = calloc(1, sizeof *result); + parse_environment(result); parse_arguments(argc, argv, result); fulfill_config(result); if (verbosity >= 3)