LCOV - code coverage report
Current view: top level - src - arlib-argp.c (source / functions) Hit Total Coverage
Test: elfutils-0.191 Lines: 2 16 12.5 %
Date: 2024-03-27 15:13:09 Functions: 1 3 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 7 14.3 %

           Branch data     Line data    Source code
       1                 :            : /* Options common to ar and ranlib.
       2                 :            :    Copyright (C) 2012 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            : 
       5                 :            :    This file is free software; you can redistribute it and/or modify
       6                 :            :    it under the terms of the GNU General Public License as published by
       7                 :            :    the Free Software Foundation; either version 3 of the License, or
       8                 :            :    (at your option) any later version.
       9                 :            : 
      10                 :            :    elfutils is distributed in the hope that it will be useful, but
      11                 :            :    WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :            :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13                 :            :    GNU General Public License for more details.
      14                 :            : 
      15                 :            :    You should have received a copy of the GNU General Public License
      16                 :            :    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
      17                 :            : 
      18                 :            : #ifdef HAVE_CONFIG_H
      19                 :            : # include <config.h>
      20                 :            : #endif
      21                 :            : 
      22                 :            : #include <argp.h>
      23                 :            : 
      24                 :            : #include "arlib.h"
      25                 :            : 
      26                 :            : bool arlib_deterministic_output = DEFAULT_AR_DETERMINISTIC;
      27                 :            : 
      28                 :            : static const struct argp_option options[] =
      29                 :            :   {
      30                 :            :     { NULL, 'D', NULL, 0,
      31                 :            :       N_("Use zero for uid, gid, and date in archive members."), 0 },
      32                 :            :     { NULL, 'U', NULL, 0,
      33                 :            :       N_("Use actual uid, gid, and date in archive members."), 0 },
      34                 :            : 
      35                 :            :     { NULL, 0, NULL, 0, NULL, 0 }
      36                 :            :   };
      37                 :            : 
      38                 :            : static error_t
      39                 :        200 : parse_opt (int key, char *arg __attribute__ ((unused)),
      40                 :            :            struct argp_state *state __attribute__ ((unused)))
      41                 :            : {
      42      [ -  -  + ]:        200 :   switch (key)
      43                 :            :     {
      44                 :          0 :     case 'D':
      45                 :          0 :       arlib_deterministic_output = true;
      46                 :          0 :       break;
      47                 :            : 
      48                 :          0 :     case 'U':
      49                 :          0 :       arlib_deterministic_output = false;
      50                 :          0 :       break;
      51                 :            : 
      52                 :            :     default:
      53                 :            :       return ARGP_ERR_UNKNOWN;
      54                 :            :     }
      55                 :            :   return 0;
      56                 :            : }
      57                 :            : 
      58                 :            : static char *
      59                 :          0 : text_for_default (const char *text)
      60                 :            : {
      61                 :          0 :   char *new_text;
      62         [ #  # ]:          0 :   if (unlikely (asprintf (&new_text, _("%s (default)"), text) < 0))
      63                 :            :     return (char *) text;
      64                 :          0 :   return new_text;
      65                 :            : }
      66                 :            : 
      67                 :            : static char *
      68                 :          0 : help_filter (int key, const char *text, void *input __attribute__ ((unused)))
      69                 :            : {
      70         [ #  # ]:          0 :   switch (key)
      71                 :            :     {
      72                 :            :     case 'D':
      73                 :            :       if (DEFAULT_AR_DETERMINISTIC)
      74                 :            :         return text_for_default (text);
      75                 :            :       break;
      76                 :            :     case 'U':
      77                 :          0 :       if (! DEFAULT_AR_DETERMINISTIC)
      78                 :          0 :         return text_for_default (text);
      79                 :            :       break;
      80                 :            :     }
      81                 :            : 
      82                 :            :   return (char *) text;
      83                 :            : }
      84                 :            : 
      85                 :            : static const struct argp argp =
      86                 :            :   {
      87                 :            :     options, parse_opt, NULL, NULL, NULL, help_filter, NULL
      88                 :            :   };
      89                 :            : 
      90                 :            : const struct argp_child arlib_argp_children[] =
      91                 :            :   {
      92                 :            :     { &argp, 0, "", 2 },
      93                 :            :     { NULL, 0, NULL, 0 }
      94                 :            :   };

Generated by: LCOV version 1.16