|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #include <stdio.h> |
|
6 #include <stdlib.h> |
|
7 #include <string.h> |
|
8 |
|
9 int |
|
10 main(int argc, char **argv) |
|
11 { |
|
12 char *curstr; |
|
13 char *nextstr; |
|
14 unsigned int firstval; |
|
15 unsigned int secondval; |
|
16 unsigned int val; |
|
17 unsigned char buf[5]; |
|
18 int count; |
|
19 |
|
20 if ( argc != 2 ) { |
|
21 fprintf(stderr, "wrong number of args\n"); |
|
22 exit(-1); |
|
23 } |
|
24 |
|
25 curstr = argv[1]; |
|
26 |
|
27 nextstr = strchr(curstr, '.'); |
|
28 |
|
29 if ( nextstr == NULL ) { |
|
30 fprintf(stderr, "only one component\n"); |
|
31 exit(-1); |
|
32 } |
|
33 |
|
34 *nextstr = '\0'; |
|
35 firstval = atoi(curstr); |
|
36 |
|
37 curstr = nextstr + 1; |
|
38 |
|
39 nextstr = strchr(curstr, '.'); |
|
40 |
|
41 if ( nextstr ) { |
|
42 *nextstr = '\0'; |
|
43 } |
|
44 |
|
45 secondval = atoi(curstr); |
|
46 |
|
47 if ( ( firstval < 0 ) || ( firstval > 2 ) ) { |
|
48 fprintf(stderr, "first component out of range\n"); |
|
49 exit(-1); |
|
50 |
|
51 } |
|
52 |
|
53 if ( ( secondval < 0 ) || ( secondval > 39 ) ) { |
|
54 fprintf(stderr, "second component out of range\n"); |
|
55 exit(-1); |
|
56 } |
|
57 |
|
58 printf("0x%x, ", ( firstval * 40 ) + secondval ); |
|
59 while ( nextstr ) { |
|
60 curstr = nextstr + 1; |
|
61 |
|
62 nextstr = strchr(curstr, '.'); |
|
63 |
|
64 if ( nextstr ) { |
|
65 *nextstr = '\0'; |
|
66 } |
|
67 |
|
68 memset(buf, 0, sizeof(buf)); |
|
69 val = atoi(curstr); |
|
70 count = 0; |
|
71 while ( val ) { |
|
72 buf[count] = ( val & 0x7f ); |
|
73 val = val >> 7; |
|
74 count++; |
|
75 } |
|
76 |
|
77 while ( count-- ) { |
|
78 if ( count ) { |
|
79 printf("0x%x, ", buf[count] | 0x80 ); |
|
80 } else { |
|
81 printf("0x%x, ", buf[count] ); |
|
82 } |
|
83 } |
|
84 } |
|
85 printf("\n"); |
|
86 return 0; |
|
87 } |
|
88 |