2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #if !defined(AFS_NT40_ENV)
18 printf("b32 not required for this operating system.\n");
30 printf("Usage: %s -s n [n ...] (converts int to base 32 string)\n", prog
);
31 printf("Usage: %s -i s [s ...] (converts base 32 string to int)\n", prog
);
32 printf("Usage: %s -c n [n ...] (converts to base 32 and back)\n", prog
);
34 ("Usage: %s -r low high inc (verify converter using range and inc)\n",
39 void btoi(int ac
, char **av
);
40 void itob(int ac
, char **av
);
41 void check(int ac
, char **av
);
42 void verifyRange(int ac
, char **av
);
45 main(int ac
, char **av
)
50 if (!strcmp(av
[1], "-s"))
52 else if (!strcmp(av
[1], "-i"))
54 else if (!strcmp(av
[1], "-c"))
56 else if (!strcmp(av
[1], "-r"))
65 btoi(int ac
, char **av
)
70 printf("%d\n", base32_to_int(av
[2]));
72 for (i
= 2; i
< ac
; i
++)
73 printf("%s: %d\n", av
[i
], base32_to_int(av
[i
]));
78 itob(int ac
, char **av
)
84 printf("%s\n", int_to_base32(str
, atoi(av
[2])));
86 for (i
= 2; i
< ac
; i
++)
87 printf("%d: %s\n", atoi(av
[i
]), int_to_base32(str
, atoi(av
[i
])));
92 check(int ac
, char **av
)
98 printf("%10s %10s %10s\n", "input", "base32", "output");
99 for (i
= 2; i
< ac
; i
++) {
101 (void)int_to_base32(str
, in
);
102 out
= base32_to_int(str
);
103 printf("%10d %10s %10d\n", in
, str
, out
);
107 #define PROGRESS 1000000
109 verifyRange(int ac
, char **av
)
111 unsigned int inc
, low
, high
;
113 unsigned int in
, out
;
119 low
= (unsigned int)atoi(av
[2]);
120 high
= (unsigned int)atoi(av
[3]);
121 inc
= (unsigned int)atoi(av
[4]);
124 for (in
= low
; in
<= high
; in
+= inc
) {
126 if (n
% PROGRESS
== 0)
128 (void)int_to_base32(str
, in
);
129 out
= base32_to_int(str
);
131 printf("\n\nERROR: in=%u, str='%s', out=%u\n", in
, str
, out
);
135 printf("\nCOMPLETE - no errors found in range %u,%u,%u\n", low
, high
,