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 26bool arlib_deterministic_output = DEFAULT_AR_DETERMINISTIC; 27 28static 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 38static error_t 39parse_opt (int key, char *arg __attribute__ ((unused)), 40 struct argp_state *state __attribute__ ((unused))) 41{ 42 switch (key) 43 { 44 case 'D': 45 arlib_deterministic_output = true; 46 break; 47 48 case 'U': 49 arlib_deterministic_output = false; 50 break; 51 52 default: 53 return ARGP_ERR_UNKNOWN; 54 } 55 return 0; 56} 57 58static char * 59text_for_default (const char *text) 60{ 61 char *new_text; 62 if (unlikely (asprintf (&new_text, _("%s (default)"), text) < 0)) 63 return (char *) text; 64 return new_text; 65} 66 67static char * 68help_filter (int key, const char *text, void *input __attribute__ ((unused))) 69{ 70 switch (key) 71 { 72 case 'D': 73 if (DEFAULT_AR_DETERMINISTIC) 74 return text_for_default (text); 75 break; 76 case 'U': 77 if (! DEFAULT_AR_DETERMINISTIC) 78 return text_for_default (text); 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 }; 95