Reduced minimum password retry level from 6 to 3
[barry/pauldeden.git] / tools / btranslate.cc
blob307b7f22f68d92509ee703d05ff2af99bf9f29d4
1 /*
2 Copyright (C) 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License in the COPYING file at the
14 root directory of this project for more details.
17 #include <iostream>
18 #include <iomanip>
19 #include <sstream>
20 #include <string.h>
21 #include <stdlib.h>
22 #include <limits.h>
24 using namespace std;
26 bool IsHexData(const char *str)
28 for( int i = 0; i < 4 && *str; str++, i++ )
29 if( *str != ' ' )
30 return false;
32 for( int i = 0; i < 8 && *str; str++, i++ )
33 if( !isdigit(*str) && !(*str >= 'a' && *str <= 'f') )
34 return false;
36 if( *str != ':' )
37 return false;
39 return true;
42 void PrintHex(const char *str)
44 cout << setiosflags(ios::left) << setw(14 + 16 * 3 + 1) << str;
45 cout << setw(0);
46 str += 14;
47 char *endpos = (char*) str;
48 while( *endpos ) {
49 long c = strtol(str, &endpos, 16);
50 if( c == LONG_MIN || c == LONG_MAX )
51 break;
52 if( isprint(c) )
53 cout << (char)c;
54 else
55 cout << '.';
56 str = endpos;
58 cout << '\n';
61 int main()
63 cout.sync_with_stdio(false);
65 while( cin ) {
66 char buff[1024];
67 cin.getline(buff, sizeof(buff));
68 if( IsHexData(buff) ) {
69 // strip whitespace
70 size_t sln = strlen(buff);
71 while( sln && (buff[sln] == 0 || isspace(buff[sln])) ){
72 buff[sln--] = 0;
74 PrintHex(buff);
76 else {
77 cout << buff << "\n";
80 if( cin.fail() && !cin.eof() ) {
81 // getline busted its buffer... discard the
82 // rest of the line.
83 while( cin.fail() && !cin.eof() ) {
84 cin.clear();
85 cin.getline(buff, sizeof(buff));