LCOV - code coverage report
Current view: top level - src - arlib-argp.c (source / functions) Hit Total Coverage
Test: elfutils-0.172 Lines: 2 15 13.3 %
Date: 2018-06-11 22:52:14 Functions: 1 3 33.3 %
Legend: Lines: hit not hit

          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             : #include <libintl.h>
      24             : 
      25             : #include "arlib.h"
      26             : 
      27             : bool arlib_deterministic_output = DEFAULT_AR_DETERMINISTIC;
      28             : 
      29             : static const struct argp_option options[] =
      30             :   {
      31             :     { NULL, 'D', NULL, 0,
      32             :       N_("Use zero for uid, gid, and date in archive members."), 0 },
      33             :     { NULL, 'U', NULL, 0,
      34             :       N_("Use actual uid, gid, and date in archive members."), 0 },
      35             : 
      36             :     { NULL, 0, NULL, 0, NULL, 0 }
      37             :   };
      38             : 
      39             : static error_t
      40          40 : parse_opt (int key, char *arg __attribute__ ((unused)),
      41             :            struct argp_state *state __attribute__ ((unused)))
      42             : {
      43          40 :   switch (key)
      44             :     {
      45           0 :     case 'D':
      46           0 :       arlib_deterministic_output = true;
      47           0 :       break;
      48             : 
      49           0 :     case 'U':
      50           0 :       arlib_deterministic_output = false;
      51           0 :       break;
      52             : 
      53             :     default:
      54             :       return ARGP_ERR_UNKNOWN;
      55             :     }
      56             :   return 0;
      57             : }
      58             : 
      59             : static char *
      60           0 : help_filter (int key, const char *text, void *input __attribute__ ((unused)))
      61             : {
      62           0 :   inline char *text_for_default (void)
      63             :   {
      64             :     char *new_text;
      65           0 :     if (unlikely (asprintf (&new_text, gettext ("%s (default)"), text) < 0))
      66           0 :       return (char *) text;
      67           0 :     return new_text;
      68             :   }
      69             : 
      70           0 :   switch (key)
      71             :     {
      72             :     case 'D':
      73             :       if (DEFAULT_AR_DETERMINISTIC)
      74             :         return text_for_default ();
      75             :       break;
      76             :     case 'U':
      77             :       if (! DEFAULT_AR_DETERMINISTIC)
      78           0 :         return text_for_default ();
      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.13