LCOV - code coverage report
Current view: top level - src - config.c (source / functions) Hit Total Coverage
Test: rapport Lines: 14 34 41.2 %
Date: 2021-12-10 16:22:55 Functions: 1 2 50.0 %
Branches: 7 18 38.9 %

           Branch data     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                 :            : 
      32                 :            : #include <pkg.h>
      33                 :            : 
      34                 :            : #include "pkgcli.h"
      35                 :            : 
      36                 :            : void
      37                 :          0 : usage_config(void)
      38                 :            : {
      39                 :          0 :         fprintf(stderr,
      40                 :            :             "Usage: pkg config <name>\n\n");
      41                 :            :         //fprintf(stderr, "For more information see 'pkg help config'.\n");
      42                 :          0 : }
      43                 :            : 
      44                 :            : int
      45                 :         72 : exec_config(int argc, char **argv)
      46                 :            : {
      47                 :            :         const pkg_object *conf, *o;
      48                 :         72 :         pkg_iter it = NULL;
      49                 :            :         const char *buf;
      50                 :            :         char *key;
      51                 :            :         int64_t integer;
      52                 :            :         int i;
      53                 :            :         bool b;
      54                 :            : 
      55         [ -  + ]:         72 :         if (argc != 2) {
      56                 :          0 :                 usage_config();
      57                 :          0 :                 return (EXIT_FAILURE);
      58                 :            :         }
      59                 :            : 
      60                 :         72 :         key = argv[1];
      61         [ +  + ]:        640 :         for (i = 0; key[i] != '\0'; i++)
      62                 :        568 :                 key[i] = toupper(key[i]);
      63                 :            : 
      64                 :         72 :         conf = pkg_config_get(key);
      65         [ +  - ]:         72 :         if (conf == NULL) {
      66                 :          0 :                 warnx("No such configuration options: %s", key);
      67                 :          0 :                 return (EXIT_FAILURE);
      68                 :            :         }
      69                 :            : 
      70   [ -  +  -  -  :         72 :         switch (pkg_object_type(conf)) {
                   -  - ]
      71                 :            :         case PKG_STRING:
      72                 :         72 :                 buf = pkg_object_string(conf);
      73         [ +  + ]:         72 :                 printf("%s\n", buf == NULL ? "" : buf);
      74                 :         72 :                 break;
      75                 :            :         case PKG_BOOL:
      76                 :          0 :                 b = pkg_object_bool(conf);
      77                 :          0 :                 printf("%s\n", b ? "yes" : "no");
      78                 :          0 :                 break;
      79                 :            :         case PKG_INT:
      80                 :          0 :                 integer = pkg_object_int(conf);
      81                 :          0 :                 printf("%"PRId64"\n", integer);
      82                 :          0 :                 break;
      83                 :            :         case PKG_OBJECT:
      84         [ #  # ]:          0 :                 while ((o = pkg_object_iterate(conf, &it))) {
      85                 :          0 :                         printf("%s: %s\n", pkg_object_key(o), pkg_object_string(o));
      86                 :            :                 }
      87                 :          0 :                 break;
      88                 :            :         case PKG_ARRAY:
      89         [ #  # ]:          0 :                 while ((o = pkg_object_iterate(conf, &it))) {
      90                 :          0 :                         printf("%s\n", pkg_object_string(o));
      91                 :            :                 }
      92                 :          0 :                 break;
      93                 :            :         default:
      94                 :          0 :                 break;
      95                 :            :         }
      96                 :            : 
      97                 :         72 :         return (EXIT_SUCCESS);
      98                 :         72 : }

Generated by: LCOV version 1.15