-
October 14th, 2013, 11:17 AM
#46
Re: Read binary file with line delimeter
Now, I only need to add the function of process that will parse each block within the while loop rigth?
I'd like to parse each block using regex.
What parsing of the block do you require?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 14th, 2013, 02:10 PM
#47
Re: Read binary file with line delimeter
Hello AceInfinity,
Thanks for try to help me too. I'll test your code either.
Hello 2kaud,
For each block I'd like first to extract some patterns with 2 regex below.
Regex1: (.{6,18})(532064[^f]*).(814[^f]*)
Regex2: ff79(0080.{4}c906)?.*?05(9.{32,34}.*?)940e(.{28})
Regex1 matches string in red
Regex2 matches string in blue
Code:
00000253206445018934551f81474554768fffff0015000a4800015a00024200016000013300013600013700015b00016600
016500017700017800017e00016900006a00007900009300012200002100010900010a001260001020001040001050001060
0011000010800012b00002c00012d00012e00015500015600072a00002f0000300000310000ff7900800932c90688888000a
000800935c90600008000000080093cc90688888000000800943c90688888000800005900f0102000000308147526905ffff
ff00910f01020000013a81475269559fffff009310010c0000009f8147526905ffffff0101960f010e000000eb8147526959
6fffff00970f0100006f69981475269563fffff00940e0001000001000100ffff0000010195060003790001ea05820037060
10000010065000000020000020018000000030000030017000000040000040001000000050000050015000000a00ffff0065
00000007802ec918009181475269539fffffff009181475269539fffff000103ca030808fecb0a00000000000000000000cc
0101811bc90b009181475269567fffffffca06000000000000cb0103cc0101
Regex1 works to extract data from the beginning of the block, for block 2 Regex1 would get:
Code:
00000253206445018934551f81474554768
but since I'm grouping with backreference, this string would be splitted like this
Code:
000002,53206445018934551,81474554768
to finally treat as hex the first group and print as decimal, leaving group 2 and group 3 without change as below.
Code:
2,53206445018934551,81474554768
For Regex2, I'm using backreference too, since I only want to extract the group 2 and 3 from Regex2. But the
parsing of string got from Regex 2 is more complicated. So, Initially I'd like to know how to apply regex on each
block.
Many thanks for the help
-
October 14th, 2013, 02:33 PM
#48
Re: Read binary file with line delimeter
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 14th, 2013, 05:03 PM
#49
Re: Read binary file with line delimeter
Hello 2kaud,
Thanks for that.
I've tried to add <regex> header but I receive error. I've read that maybe with visual studio compiler could work.
I've downloaded and installed a visual C++ 2012 compiler version but I'm no able to make that works with netbeans nor Dev C++.
Does accepts for you the regex header? Which IDE and compiler are you using?
Thanks in advance
-
October 14th, 2013, 06:07 PM
#50
Re: Read binary file with line delimeter
I'm using VS 2013 and am able to use the <regex> header with this setup. Dev C++ is old (assuming you're using bloodshed's, and not orwells), and if so, you should abandon it.
[sigpic][/sigpic]
Microsoft MVP .NET Programming (2012 - Present)
®Crestron DMC-T Certified Automation Programmer
-
October 14th, 2013, 06:20 PM
#51
Re: Read binary file with line delimeter
Thanks for the answer.
I'm testing with netbeans and Orwells Dev C++.
Since MSVS is payed, do you know another IDE or compiler that let me use regex?
Thanks again
-
October 14th, 2013, 06:37 PM
#52
Re: Read binary file with line delimeter
Originally Posted by Philidor
Thanks for the answer.
I'm testing with netbeans and Orwells Dev C++.
Since MSVS is payed, do you know another IDE or compiler that let me use regex?
Thanks again
You're assuming that it's a paid software. There are express editions of Visual Studio for 2013 which are free.
[sigpic][/sigpic]
Microsoft MVP .NET Programming (2012 - Present)
®Crestron DMC-T Certified Automation Programmer
-
October 14th, 2013, 11:28 PM
#53
Re: Read binary file with line delimeter
Hello Ace
I've installed MSVS 2013 and I've been trying to test regex using the example for the below page, bu I get errors when
compile.
http://en.cppreference.com/w/cpp/reg...ax_option_type
I'm not sure why, I did this: New project --> Visual C++-->CLR-->CLR Console Application.
-
October 14th, 2013, 11:59 PM
#54
Re: Read binary file with line delimeter
CLR, why do you want that? Try "Win32 Project" instead. What errors are you getting? You just posted a reference link, but nothing that describes the errors.
Last edited by AceInfinity; October 15th, 2013 at 12:02 AM.
[sigpic][/sigpic]
Microsoft MVP .NET Programming (2012 - Present)
®Crestron DMC-T Certified Automation Programmer
-
October 15th, 2013, 05:00 AM
#55
Re: Read binary file with line delimeter
Since MSVS is payed, do you know another IDE or compiler that let me use regex?
gcc is free and is c++11 compliant
http://gcc.gnu.org/
(see top of news left hand side regarding support for regex!)
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 15th, 2013, 06:39 PM
#56
Re: Read binary file with line delimeter
Originally Posted by AceInfinity
CLR, why do you want that? Try "Win32 Project" instead. What errors are you getting? You just posted a reference link, but nothing that describes the errors.
Thanks!. Only I didn't know what option to choose. I'll test as you say.
Originally Posted by 2kaud
gcc is free and is c++11 compliant
http://gcc.gnu.org/
(see top of news left hand side regarding support for regex!)
Thanks 2kaud, I'll try to download and see if I'm able to make it work this compiler.
Thanks again for the help.
-
October 16th, 2013, 06:32 PM
#57
Re: Read binary file with line delimeter
Hello 2kaud
I've been searching and it seems gcc doesn't support yet regex . It seems only basic things.
http://gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/onlinedocs/libstd...tatus.iso.200x
I found that clang is full C++11, but it seems it works for linux. I'll continue searching.
-
October 18th, 2013, 10:38 AM
#58
Re: Read binary file with line delimeter
Hello 2kaud again,
I see that each block is printed in the for loop using "display(bv)", but I'd like to store in a single string each block
to be able to process it. I'd like to modificate the display function in order to have in a string each block, something like
below but I don't know how would be the correct way and how to retrieve that string in main function.
Code:
void display(const bVec bv)
{
for (int i = 0; i < bv.size(); i++)
//cout << setw(2) << setfill('0') << hex << (int)bv[i];
Block= Block + (int)bv[i];
}
I hopw you can help me with this.
Thanks in advance.
-
October 18th, 2013, 11:35 AM
#59
Re: Read binary file with line delimeter
bv is a vector of BYTE (unsigned char) that can be processed. If you want a string of hex equivalent then one way is
Code:
void display(const bVec& bv)
{
for (int i = 0; i < bv.size(); i++)
cout << setw(2) << setfill('0') << hex << (int)bv[i];
cout << endl << endl;
}
void conString(const bVec& bv, string& block)
{
ostringstream ss;
for (int i = 0; i < bv.size(); i++)
ss << setw(2) << setfill('0') << hex << (int)bv[i];
block = ss.str();
}
int main()
{
FileFields ff;
bVec bv;
int blk = 0;
string block;
if (!ff.open("binary.txt")) {
cout << "Cannot open file!" << endl;
return 1;
}
while (ff.getField(bv)) {
cout << "block " << blk++ << endl;
//display(bv);
conString(bv, block);
cout << block << endl << endl;
}
return 0;
}
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 18th, 2013, 01:22 PM
#60
Re: Read binary file with line delimeter
Hello 2kaud,
Thanks for your help. Ive tried but in compilation I get the error:
Code:
[Error] aggregate 'std::ostringstream ss' has incomplete type and cannot be defined
I've added "std::" but the same error.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|