2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
20 #define POST_DEFAULT_IO_PORT 0x80
22 void usage(char *progname
, const char *error
, ...)
24 printf("Usage: %s <VALUE> [PORT]\n", progname
);
25 printf("The VALUE argument is an integer between 0x00 and 0xff\n");
26 printf("The PORT argument is an integer between 0x00 and 0xffff\n");
31 va_start(args
, error
);
37 void check_int(long val
, int min
, int max
, int err
, char *string
, char *endptr
,
40 if (val
< min
|| val
> max
) {
42 "\nError: The value has to be between 0x%x and 0x%x\n",
47 if (endptr
== string
|| *endptr
!= '\0') {
48 usage(progname
, "\nError: An integer is required\n");
52 if ((err
) && (!val
)) {
58 int main(int argc
, char *argv
[])
61 unsigned long port
= POST_DEFAULT_IO_PORT
;
65 if (argc
!= 2 && argc
!= 3) {
70 val
= strtol(argv
[1], &endptr
, 0);
72 check_int(val
, 0x00, 0xff, err
, argv
[1], endptr
, argv
[0]);
75 port
= strtol(argv
[2], &endptr
, 0);
77 check_int(port
, 0x0000, 0xffff, err
, argv
[2], endptr
, argv
[0]);