Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

verstring.cc

Go to the documentation of this file.
00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * Version number and string manipulations. Version numbers are 32-bit 00006 * hexadecimal numbers such as 0x00012a00. The first 16 bits are the major 00007 * version, and the second 16 bits are the (fractional) minor version. For 00008 * example, the above example corresponds to version "1.2a" (which is the 00009 * version string). 00010 */ 00011 #include "verstring.h" 00012 #include <stdio.h> 00013 #include <ctype.h> 00014 #include <string.h> 00015 00016 const char *ver_to_string(unsigned int ver) 00017 { 00018 static char str[10]; 00019 unsigned int maj = (ver & 0xFFFF0000) >> 16, min = (ver & 0x0000FFFF); 00020 char *cptr; 00021 00022 sprintf(str, "%x.%04x", maj, min); 00023 00024 // trim off trailing zeroes from minor number 00025 for (cptr = strchr(str, 0); --cptr >= str; ) 00026 { 00027 if (*cptr != '0') 00028 break; 00029 00030 if (cptr <= str || *(cptr - 1) == '.') 00031 break; 00032 00033 *cptr = 0; 00034 } 00035 00036 return str; 00037 } 00038 00039 00040 unsigned int string_to_ver(const char *str) 00041 { 00042 static char lookup[] = "0123456789abcdef"; 00043 unsigned int maj = 0, min = 0; 00044 unsigned char *cptr, *idx; 00045 int bits; 00046 00047 // do the major number 00048 cptr = (unsigned char *)str; 00049 for (; *cptr && *cptr != '.' && *cptr != '_'; cptr++) 00050 { 00051 idx = (unsigned char *)strchr(lookup, tolower(*cptr)); 00052 if (!idx) 00053 continue; 00054 00055 maj = (maj << 4) | ((char *)idx - lookup); 00056 } 00057 00058 // do the minor number 00059 for (bits = 4; *cptr && bits > 0; cptr++) 00060 { 00061 idx = (unsigned char *)strchr(lookup, tolower(*cptr)); 00062 if (!idx) 00063 continue; 00064 00065 min = (min << 4) | ((char *)idx - lookup); 00066 bits--; 00067 } 00068 00069 return (maj << 16) | (min << (4*bits)); 00070 }

Generated on Tue Oct 5 01:09:19 2004 for WvStreams by doxygen 1.3.7