main: implement --define-variable

pull/15/head
William Pitcock 2012-05-06 23:32:08 -05:00
parent 97afd424b1
commit 7ae5ccd177
3 changed files with 22 additions and 0 deletions

5
main.c
View File

@ -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;
}

1
pkg.h
View File

@ -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

16
tuple.c
View File

@ -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)
{