diff --git a/main.c b/main.c index 8ca82fc..405c9a3 100644 --- a/main.c +++ b/main.c @@ -452,6 +452,7 @@ usage(void) printf("\nquerying specific pkg-config database fields:\n\n"); + printf(" --define-variable=varname=value define variable 'varname' as 'value'\n"); printf(" --variable=varname print specified variable entry to stdout\n"); printf(" --cflags print required CFLAGS to stdout\n"); printf(" --cflags-only-I print required include-dir CFLAGS to stdout\n"); @@ -506,6 +507,7 @@ main(int argc, char *argv[]) { "no-uninstalled", no_argument, &want_no_uninstalled, 25, }, { "keep-system-cflags", no_argument, &want_keep_system_cflags, 26, }, { "keep-system-libs", no_argument, &want_keep_system_libs, 26, }, + { "define-variable", required_argument, NULL, 27, }, { NULL, 0, NULL, 0 } }; @@ -525,6 +527,9 @@ main(int argc, char *argv[]) case 11: maximum_traverse_depth = atoi(optarg); break; + case 27: + pkg_tuple_define_global(optarg); + break; default: break; } diff --git a/pkg.h b/pkg.h index 426929f..acafe89 100644 --- a/pkg.h +++ b/pkg.h @@ -169,5 +169,6 @@ void pkg_tuple_free(pkg_tuple_t *head); void pkg_tuple_add_global(const char *key, const char *value); char *pkg_tuple_find_global(const char *key); void pkg_tuple_free_global(void); +void pkg_tuple_define_global(const char *kv); #endif diff --git a/tuple.c b/tuple.c index 820fd89..12c7a52 100644 --- a/tuple.c +++ b/tuple.c @@ -52,6 +52,22 @@ pkg_tuple_free_global(void) pkg_tuple_free(pkg_global_var); } +void +pkg_tuple_define_global(const char *kv) +{ + char *workbuf = strdup(kv); + char *value; + + value = strchr(workbuf, '='); + if (value == NULL) + goto out; + + *value++ = '\0'; + pkg_tuple_add_global(workbuf, value); +out: + free(workbuf); +} + pkg_tuple_t * pkg_tuple_add(pkg_tuple_t *parent, const char *key, const char *value) {