summaryrefslogtreecommitdiff
path: root/src/arlib-argp.c
blob: a0e669cf5c869130b904dfc9dde54fbe0af9ad0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Options common to ar and ranlib.
   Copyright (C) 2012 Red Hat, Inc.

   Red Hat elfutils is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by the
   Free Software Foundation; version 2 of the License.

   Red Hat elfutils is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with Red Hat elfutils; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.

   Red Hat elfutils is an included package of the Open Invention Network.
   An included package of the Open Invention Network is a package for which
   Open Invention Network licensees cross-license their patents.  No patent
   license is granted, either expressly or impliedly, by designation as an
   included package.  Should you wish to participate in the Open Invention
   Network licensing program, please visit www.openinventionnetwork.com
   <http://www.openinventionnetwork.com>.  */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <argp.h>
#include <libintl.h>

#include "arlib.h"

bool arlib_deterministic_output = DEFAULT_AR_DETERMINISTIC;

static const struct argp_option options[] =
  {
    { NULL, 'D', NULL, 0,
      N_("Use zero for uid, gid, and date in archive members."), 0 },
    { NULL, 'U', NULL, 0,
      N_("Use actual uid, gid, and date in archive members."), 0 },

    { NULL, 0, NULL, 0, NULL, 0 }
  };

static error_t
parse_opt (int key, char *arg __attribute__ ((unused)),
           struct argp_state *state __attribute__ ((unused)))
{
  switch (key)
    {
    case 'D':
      arlib_deterministic_output = true;
      break;

    case 'U':
      arlib_deterministic_output = false;
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static char *
help_filter (int key, const char *text, void *input __attribute__ ((unused)))
{
  inline char *text_for_default (void)
  {
    char *new_text;
    if (unlikely (asprintf (&new_text, gettext ("%s (default)"), text) < 0))
      return (char *) text;
    return new_text;
  }

  switch (key)
    {
    case 'D':
      if (DEFAULT_AR_DETERMINISTIC)
        return text_for_default ();
      break;
    case 'U':
      if (! DEFAULT_AR_DETERMINISTIC)
        return text_for_default ();
      break;
    }

  return (char *) text;
}

static const struct argp argp =
  {
    options, parse_opt, NULL, NULL, NULL, help_filter, NULL
  };

const struct argp_child arlib_argp_children[] =
  {
    { &argp, 0, "", 2 },
    { NULL, 0, NULL, 0 }
  };