michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: int michael@0: main(int argc, char **argv) michael@0: { michael@0: char *curstr; michael@0: char *nextstr; michael@0: unsigned int firstval; michael@0: unsigned int secondval; michael@0: unsigned int val; michael@0: unsigned char buf[5]; michael@0: int count; michael@0: michael@0: if ( argc != 2 ) { michael@0: fprintf(stderr, "wrong number of args\n"); michael@0: exit(-1); michael@0: } michael@0: michael@0: curstr = argv[1]; michael@0: michael@0: nextstr = strchr(curstr, '.'); michael@0: michael@0: if ( nextstr == NULL ) { michael@0: fprintf(stderr, "only one component\n"); michael@0: exit(-1); michael@0: } michael@0: michael@0: *nextstr = '\0'; michael@0: firstval = atoi(curstr); michael@0: michael@0: curstr = nextstr + 1; michael@0: michael@0: nextstr = strchr(curstr, '.'); michael@0: michael@0: if ( nextstr ) { michael@0: *nextstr = '\0'; michael@0: } michael@0: michael@0: secondval = atoi(curstr); michael@0: michael@0: if ( ( firstval < 0 ) || ( firstval > 2 ) ) { michael@0: fprintf(stderr, "first component out of range\n"); michael@0: exit(-1); michael@0: michael@0: } michael@0: michael@0: if ( ( secondval < 0 ) || ( secondval > 39 ) ) { michael@0: fprintf(stderr, "second component out of range\n"); michael@0: exit(-1); michael@0: } michael@0: michael@0: printf("0x%x, ", ( firstval * 40 ) + secondval ); michael@0: while ( nextstr ) { michael@0: curstr = nextstr + 1; michael@0: michael@0: nextstr = strchr(curstr, '.'); michael@0: michael@0: if ( nextstr ) { michael@0: *nextstr = '\0'; michael@0: } michael@0: michael@0: memset(buf, 0, sizeof(buf)); michael@0: val = atoi(curstr); michael@0: count = 0; michael@0: while ( val ) { michael@0: buf[count] = ( val & 0x7f ); michael@0: val = val >> 7; michael@0: count++; michael@0: } michael@0: michael@0: while ( count-- ) { michael@0: if ( count ) { michael@0: printf("0x%x, ", buf[count] | 0x80 ); michael@0: } else { michael@0: printf("0x%x, ", buf[count] ); michael@0: } michael@0: } michael@0: } michael@0: printf("\n"); michael@0: return 0; michael@0: } michael@0: