blob: 1bdd8d0b2de2545a0654b3a15024d5df0c877654 [file] [log] [blame]
Brian Silverman86497922018-02-10 19:28:39 -05001/* 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
27bool arlib_deterministic_output = DEFAULT_AR_DETERMINISTIC;
28
29static 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
39static error_t
40parse_opt (int key, char *arg __attribute__ ((unused)),
41 struct argp_state *state __attribute__ ((unused)))
42{
43 switch (key)
44 {
45 case 'D':
46 arlib_deterministic_output = true;
47 break;
48
49 case 'U':
50 arlib_deterministic_output = false;
51 break;
52
53 default:
54 return ARGP_ERR_UNKNOWN;
55 }
56 return 0;
57}
58
59static char *
60help_filter (int key, const char *text, void *input __attribute__ ((unused)))
61{
62 inline char *text_for_default (void)
63 {
64 char *new_text;
65 if (unlikely (asprintf (&new_text, gettext ("%s (default)"), text) < 0))
66 return (char *) text;
67 return new_text;
68 }
69
70 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 return text_for_default ();
79 break;
80 }
81
82 return (char *) text;
83}
84
85static const struct argp argp =
86 {
87 options, parse_opt, NULL, NULL, NULL, help_filter, NULL
88 };
89
90const struct argp_child arlib_argp_children[] =
91 {
92 { &argp, 0, "", 2 },
93 { NULL, 0, NULL, 0 }
94 };