LCOV - code coverage report
Current view: top level - src - config.c (source / functions) Hit Total Coverage
Test: cov.info Lines: 13 33 39.4 %
Date: 2015-08-15 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*-
       2             :  * Copyright (c) 2013 Baptiste Daroussin <bapt@FreeBSD.org>
       3             :  * All rights reserved.
       4             :  * 
       5             :  * Redistribution and use in source and binary forms, with or without
       6             :  * modification, are permitted provided that the following conditions
       7             :  * are met:
       8             :  * 1. Redistributions of source code must retain the above copyright
       9             :  *    notice, this list of conditions and the following disclaimer
      10             :  *    in this position and unchanged.
      11             :  * 2. Redistributions in binary form must reproduce the above copyright
      12             :  *    notice, this list of conditions and the following disclaimer in the
      13             :  *    documentation and/or other materials provided with the distribution.
      14             :  * 
      15             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
      16             :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      17             :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      18             :  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
      19             :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      20             :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      21             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      22             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      23             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      24             :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      25             :  */
      26             : 
      27             : #include <ctype.h>
      28             : #include <err.h>
      29             : #include <inttypes.h>
      30             : #include <stdio.h>
      31             : #include <sysexits.h>
      32             : 
      33             : #include <pkg.h>
      34             : 
      35             : #include "pkgcli.h"
      36             : 
      37             : void
      38           0 : usage_config(void)
      39             : {
      40           0 :         fprintf(stderr,
      41             :             "Usage: pkg config <configname>\n\n");
      42             :         //fprintf(stderr, "For more information see 'pkg help config'.\n");
      43           0 : }
      44             : 
      45             : int
      46           1 : exec_config(int argc, char **argv)
      47             : {
      48             :         const pkg_object *conf, *o;
      49           1 :         pkg_iter it = NULL;
      50             :         const char *buf;
      51             :         char *key;
      52             :         int64_t integer;
      53             :         int i;
      54             :         bool b;
      55             : 
      56           1 :         if (argc != 2) {
      57           0 :                 usage_config();
      58           0 :                 return (EX_USAGE);
      59             :         }
      60             : 
      61           1 :         key = argv[1];
      62          10 :         for (i = 0; key[i] != '\0'; i++)
      63           9 :                 key[i] = toupper(key[i]);
      64             : 
      65           1 :         conf = pkg_config_get(key);
      66           1 :         if (conf == NULL) {
      67           0 :                 warnx("No such configuration options: %s", key);
      68           0 :                 return (EX_SOFTWARE);
      69             :         }
      70             : 
      71           1 :         switch (pkg_object_type(conf)) {
      72             :         case PKG_STRING:
      73           1 :                 buf = pkg_object_string(conf);
      74           1 :                 printf("%s\n", buf == NULL ? "" : buf);
      75           1 :                 break;
      76             :         case PKG_BOOL:
      77           0 :                 b = pkg_object_bool(conf);
      78           0 :                 printf("%s\n", b ? "yes" : "no");
      79           0 :                 break;
      80             :         case PKG_INT:
      81           0 :                 integer = pkg_object_int(conf);
      82           0 :                 printf("%"PRId64"\n", integer);
      83           0 :                 break;
      84             :         case PKG_OBJECT:
      85           0 :                 while ((o = pkg_object_iterate(conf, &it))) {
      86           0 :                         printf("%s: %s\n", pkg_object_key(o), pkg_object_string(o));
      87             :                 }
      88           0 :                 break;
      89             :         case PKG_ARRAY:
      90           0 :                 while ((o = pkg_object_iterate(conf, &it))) {
      91           0 :                         printf("%s\n", pkg_object_string(o));
      92             :                 }
      93           0 :                 break;
      94             :         default:
      95           0 :                 break;
      96             :         }
      97             : 
      98           1 :         return (EX_OK);
      99             : }

Generated by: LCOV version 1.10