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.
15 static char buf
[1000];
17 int arg_to_int(const char *s
)
23 val
= strtol(s
, &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
));
29 tap_bail_out("%s: %s", s
, strerror(errno
));
34 int main(int argc
, char **argv
)
40 len
= fread(buf
, 1, sizeof buf
- 1, stdin
);
41 if (len
== sizeof buf
- 1)
42 tap_bail_out("too much input text");
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
);