| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <config.h> |
| 20 |
#include "xstrtol.h" |
| 21 |
|
| 22 |
#include <stdlib.h> |
| 23 |
|
| 24 |
#include "error.h" |
| 25 |
#include "exitfail.h" |
| 26 |
#include "gettext.h" |
| 27 |
|
| 28 |
#define N_(msgid) msgid |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
static void |
| 47 |
xstrtol_error (enum strtol_error err, |
| 48 |
int opt_idx, char c, struct option const *long_options, |
| 49 |
char const *arg, |
| 50 |
int exit_status) |
| 51 |
{ |
| 52 |
char const *hyphens = "--"; |
| 53 |
char const *msgid; |
| 54 |
char const *option; |
| 55 |
char option_buffer[2]; |
| 56 |
|
| 57 |
switch (err) |
| 58 |
{ |
| 59 |
default: |
| 60 |
abort (); |
| 61 |
|
| 62 |
case LONGINT_INVALID: |
| 63 |
msgid = N_("invalid %s%s argument '%s'"); |
| 64 |
break; |
| 65 |
|
| 66 |
case LONGINT_INVALID_SUFFIX_CHAR: |
| 67 |
case LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW: |
| 68 |
msgid = N_("invalid suffix in %s%s argument '%s'"); |
| 69 |
break; |
| 70 |
|
| 71 |
case LONGINT_OVERFLOW: |
| 72 |
msgid = N_("%s%s argument '%s' too large"); |
| 73 |
break; |
| 74 |
} |
| 75 |
|
| 76 |
if (opt_idx < 0) |
| 77 |
{ |
| 78 |
hyphens -= opt_idx; |
| 79 |
option_buffer[0] = c; |
| 80 |
option_buffer[1] = '\0'; |
| 81 |
option = option_buffer; |
| 82 |
} |
| 83 |
else |
| 84 |
option = long_options[opt_idx].name; |
| 85 |
|
| 86 |
error (exit_status, 0, gettext (msgid), hyphens, option, arg); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
void |
| 92 |
xstrtol_fatal (enum strtol_error err, |
| 93 |
int opt_idx, char c, struct option const *long_options, |
| 94 |
char const *arg) |
| 95 |
{ |
| 96 |
xstrtol_error (err, opt_idx, c, long_options, arg, exit_failure); |
| 97 |
abort (); |
| 98 |
} |