/*-1* Copyright (c) 2013 Baptiste Daroussin <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer9* in this position and unchanged.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,18* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#include <ctype.h>27#include <err.h>28#include <inttypes.h>29#include <stdio.h>3031#include <pkg.h>3233#include "pkgcli.h"3435void36usage_config(void)37{38fprintf(stderr,39"Usage: pkg config <name>\n\n");40//fprintf(stderr, "For more information see 'pkg help config'.\n");41}4243int44exec_config(int argc, char **argv)45{46const pkg_object *conf, *o;47pkg_iter it = NULL;48const char *buf;49char *key;50int64_t integer;51int i;52bool b;5354if (argc != 2) {55usage_config();56return (EXIT_FAILURE);57}5859key = argv[1];60for (i = 0; key[i] != '\0'; i++)61key[i] = toupper(key[i]);6263conf = pkg_config_get(key);64if (conf == NULL) {65warnx("No such configuration options: %s", key);66return (EXIT_FAILURE);67}6869switch (pkg_object_type(conf)) {70case PKG_STRING:71buf = pkg_object_string(conf);72printf("%s\n", buf == NULL ? "" : buf);73break;74case PKG_BOOL:75b = pkg_object_bool(conf);76printf("%s\n", b ? "yes" : "no");77break;78case PKG_INT:79integer = pkg_object_int(conf);80printf("%"PRId64"\n", integer);81break;82case PKG_OBJECT:83while ((o = pkg_object_iterate(conf, &it))) {84printf("%s: %s\n", pkg_object_key(o), pkg_object_string(o));85}86break;87case PKG_ARRAY:88while ((o = pkg_object_iterate(conf, &it))) {89printf("%s\n", pkg_object_string(o));90}91break;92default:93break;94}9596return (EXIT_SUCCESS);97}9899100