00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <iostream>
00018 #include <iomanip>
00019 #include <sstream>
00020 #include <string.h>
00021 #include <stdlib.h>
00022 #include <limits.h>
00023
00024 using namespace std;
00025
00026 bool IsHexData(const char *str)
00027 {
00028 for( int i = 0; i < 4 && *str; str++, i++ )
00029 if( *str != ' ' )
00030 return false;
00031
00032 for( int i = 0; i < 8 && *str; str++, i++ )
00033 if( !isdigit(*str) && !(*str >= 'a' && *str <= 'f') )
00034 return false;
00035
00036 if( *str != ':' )
00037 return false;
00038
00039 return true;
00040 }
00041
00042 void PrintHex(const char *str)
00043 {
00044 cout << setiosflags(ios::left) << setw(14 + 16 * 3 + 1) << str;
00045 cout << setw(0);
00046 str += 14;
00047 char *endpos = (char*) str;
00048 while( *endpos ) {
00049 long c = strtol(str, &endpos, 16);
00050 if( c == LONG_MIN || c == LONG_MAX )
00051 break;
00052 if( isprint(c) )
00053 cout << (char)c;
00054 else
00055 cout << '.';
00056 str = endpos;
00057 }
00058 cout << '\n';
00059 }
00060
00061 int main()
00062 {
00063 cout.sync_with_stdio(false);
00064
00065 while( cin ) {
00066 char buff[1024];
00067 cin.getline(buff, sizeof(buff));
00068 if( IsHexData(buff) ) {
00069
00070 size_t sln = strlen(buff);
00071 while( sln && (buff[sln] == 0 || isspace(buff[sln])) ){
00072 buff[sln--] = 0;
00073 }
00074 PrintHex(buff);
00075 }
00076 else {
00077 cout << buff << "\n";
00078 }
00079
00080 if( cin.fail() && !cin.eof() ) {
00081
00082
00083 while( cin.fail() && !cin.eof() ) {
00084 cin.clear();
00085 cin.getline(buff, sizeof(buff));
00086 }
00087 }
00088 }
00089 }
00090