gen-options.awk: Avoid translation context for help strings.
[dxcommon.git] / t / helpdesc.c
blob923dd2f11534c947f82238fc171e4849e6d60034
1 /*
2 * Read some text from standard input and format it with help_print_desc,
3 * for testing. Each pair of program arguments is converted to an int and
4 * passed as the two integer arguments to help_print_desc.
5 */
6 #include "help.h"
7 #include "tap.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <limits.h>
13 #include <errno.h>
15 static char buf[1000];
17 int arg_to_int(const char *s)
19 char *end;
20 long val;
22 errno = 0;
23 val = strtol(s, &end, 0);
24 if (*end != 0)
25 tap_bail_out("%s: numeric argument expected", s);
26 else if (val < INT_MIN || val > INT_MAX || errno == ERANGE)
27 tap_bail_out("%s: %s", s, strerror(ERANGE));
28 else if (errno)
29 tap_bail_out("%s: %s", s, strerror(errno));
31 return val;
34 int main(int argc, char **argv)
36 long a, b;
37 size_t len;
38 int i;
40 len = fread(buf, 1, sizeof buf - 1, stdin);
41 if (len == sizeof buf - 1)
42 tap_bail_out("too much input text");
43 if (ferror(stdin))
44 tap_bail_out("error reading from stdin: %s", strerror(errno));
46 for (i = 1; i < argc; i += 2) {
47 int indent = arg_to_int(argv[i]);
48 int sub = i+1 < argc ? arg_to_int(argv[i+1]) : 0;
50 help_print_desc(NULL, buf, indent, sub);
53 return 0;