2 // ktrans.cc - print human readable version of usbfs_snoop kernel log
6 Copyright (C) 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the GNU General Public License in the COPYING file at the
18 root directory of this project for more details.
26 #include <barry/data.h>
32 cout
<< "ktrans - usbfs_snoop kernel log translator\n"
34 "\tUsage: ktrans logmarker < log\n"
36 "\tExample: ktrans \"kernel: \" < /var/log/kern.log\n"
40 bool IsHexData(const char *logmarker
, const char *str
)
42 str
= strstr(str
, logmarker
);
45 str
+= strlen(logmarker
);
47 if( strstr(str
, "data ") || strstr(str
, "data: ") ) {
48 // looks like a data line, make sure data from there on out
52 str
= strstr(str
, "data") + 4;
53 for( ; *str
== ':' || *str
== ' '; str
++ )
57 if( !( isdigit(*str
) || *str
== ' ' ||
58 (*str
>= 'a' && *str
<= 'f')) )
67 if( !( isdigit(*str
) || *str
== ' ' ||
68 (*str
>= 'a' && *str
<= 'f')) )
72 return true; // all data is numeric, so this is a continuation line
76 void SplitHex(const char *logmarker
, const char *str
, Barry::Data
&data
)
78 const char *hexptr
= strstr(str
, logmarker
);
83 hexptr
+= strlen(logmarker
);
84 std::string
readable(str
, hexptr
- str
);
88 hexptr
= strstr(str
, "data ");
93 hexptr
= strstr(str
, "data: ");
101 for( ; *hexptr
== ':' || *hexptr
== ' '; hexptr
++ )
104 readable
.append(str
, hexptr
- str
);
105 cout
<< readable
<< endl
;
107 data
.AppendHexString(hexptr
);
110 int main(int argc
, char *argv
[])
112 cout
.sync_with_stdio(false);
123 if( IsHexData(argv
[1], buff
.c_str()) ) {
124 SplitHex(argv
[1], buff
.c_str(), data
);
127 if( data
.GetSize() ) {
131 cout
<< buff
<< "\n";
135 if( data
.GetSize() ) {