Correct ctime arguments
[openafs.git] / src / util / test / b32.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <stdio.h>
15 #if !defined(AFS_NT40_ENV)
16 main()
17 {
18     printf("b32 not required for this operating system.\n");
19     exit(1);
20 }
21 #else
22
23 #include "afsutil.h"
24
25 char *prog = "b32";
26
27 void
28 Usage(void)
29 {
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);
33     printf
34         ("Usage: %s -r low high inc (verify converter using range and inc)\n",
35          prog);
36     exit(1);
37 }
38
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);
43
44
45 main(int ac, char **av)
46 {
47     if (ac < 3)
48         Usage();
49
50     if (!strcmp(av[1], "-s"))
51         itob(ac, av);
52     else if (!strcmp(av[1], "-i"))
53         btoi(ac, av);
54     else if (!strcmp(av[1], "-c"))
55         check(ac, av);
56     else if (!strcmp(av[1], "-r"))
57         verifyRange(ac, av);
58     else
59         Usage();
60
61     exit(0);
62 }
63
64 void
65 btoi(int ac, char **av)
66 {
67     int i;
68
69     if (ac == 3)
70         printf("%d\n", base32_to_int(av[2]));
71     else {
72         for (i = 2; i < ac; i++)
73             printf("%s: %d\n", av[i], base32_to_int(av[i]));
74     }
75 }
76
77 void
78 itob(int ac, char **av)
79 {
80     int i;
81     b32_string_t str;
82
83     if (ac == 3)
84         printf("%s\n", int_to_base32(str, atoi(av[2])));
85     else {
86         for (i = 2; i < ac; i++)
87             printf("%d: %s\n", atoi(av[i]), int_to_base32(str, atoi(av[i])));
88     }
89 }
90
91 void
92 check(int ac, char **av)
93 {
94     int i;
95     int in, out;
96     b32_string_t str;
97
98     printf("%10s %10s %10s\n", "input", "base32", "output");
99     for (i = 2; i < ac; i++) {
100         in = atoi(av[i]);
101         (void)int_to_base32(str, in);
102         out = base32_to_int(str);
103         printf("%10d %10s %10d\n", in, str, out);
104     }
105 }
106
107 #define PROGRESS 1000000
108 void
109 verifyRange(int ac, char **av)
110 {
111     unsigned int inc, low, high;
112     int n;
113     unsigned int in, out;
114     b32_string_t str;
115
116     if (ac != 5)
117         Usage();
118
119     low = (unsigned int)atoi(av[2]);
120     high = (unsigned int)atoi(av[3]);
121     inc = (unsigned int)atoi(av[4]);
122
123     n = 0;
124     for (in = low; in <= high; in += inc) {
125         n++;
126         if (n % PROGRESS == 0)
127             printf(" %d", n);
128         (void)int_to_base32(str, in);
129         out = base32_to_int(str);
130         if (in != out) {
131             printf("\n\nERROR: in=%u, str='%s', out=%u\n", in, str, out);
132             exit(1);
133         }
134     }
135     printf("\nCOMPLETE - no errors found in range %u,%u,%u\n", low, high,
136            inc);
137 }
138
139
140 #endif /* !NT */