This example parses a Windows resource dialog file (rc) in the format created with:
https://fbedit.svn.sourceforge.net/s...Ed22/ResEd.zip
This editor allows the style and exestyle to be saved as hex.
It was tested with the MINGW distro from nuwen as it has pcre3 included.
MinGW Distro - nuwen.net
I also tested with the TDM-GCC distro but I had to build the pcre3 library.
I am not too versed with the pcre3 library, just enough to use it a bit.
I tried to show here a bit of the C++ wrapper.
James
Code:
//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// tested with NUWEN and TDM-GCC compilers
// make sure to use -lpcrecpp -lpcre -DPCRE_STATIC when compiling
//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#include "pcrecpp.h"
#define WAITKEY system("pause")
void cls (void)
{
system("cls");
}
//==============================================================================
int main ()
{
vector<string> Linesvec;
string sFileIn="DLG2SRC.rc";
string sLine;
string sStyle;
string sExStyle;
int Start={0};
int rc={0};
int i={0};
pcrecpp::RE* re[3];
string S1[10];
ifstream f;
//id name and value
re[0]= new pcrecpp::RE("(?i)#define\\s*(\\w+)\\s*(\\d+)");
//'Dialog info
re[1]= new pcrecpp::RE("(?i)\\s*(\\w*)\\s*(DIALOGEX|DIALOG)\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)");
// Control Information
re[2]= new pcrecpp::RE("(?i)\\s*CONTROL\\s+\\x22\\s*([^\\x22\\r\\n]*)\\s*\\x22\\s*,\\s*(\\w*)\\s*,\\x22(\\s*\\w+)\\x22\\s*,([a-fx0-9]+)\\s*,(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,+\\s*(\\d+)\\s*(,+([a-fx0-9]*)\\s*)?");
// Open File
f.open(sFileIn);
// Is it open? if not time to exit
if(!f.is_open())
{
cout << "Could not locate " << sFileIn << endl;
WAITKEY;
return 0;
}
// Get each line and stuff it in a vector
while(getline(f,sLine))
{
Linesvec.push_back(sLine);
}
//close the rc file
f.close();
/*
------------------------------------------------------------------------------
Get Id names and values from rc file
------------------------------------------------------------------------------
*/
cout << " Control Dialog Names and Values" << endl;
cout << "----------------------------------" << endl;
// C++11 range based for with auto data type detection for iterator
for(auto it : Linesvec)
{
rc= re[0]->FullMatch( it, &S1[0], &S1[1]);
if(rc )
{
cout << S1[0] << " = " << S1[1] << endl;
}
}
WAITKEY;
cls();
for( auto it : Linesvec)
{
rc= re[1]->FullMatch( it, &S1[0], &S1[1], &S1[2], &S1[3], &S1[4], &S1[5]);
if(rc )
{
cout << "----------------------------------" << endl;
cout << "Dialog Information" << endl;
cout << "----------------------------------" << endl;
cout << "Dialog Name " << S1[0] << endl;
cout << "Dialog Type " << S1[1] << endl;
cout << "Dialog Left " << S1[2] << endl;
cout << "Dialog Top " << S1[3] << endl;
cout << "Dialog Width " << S1[4] << endl;
cout << "Dialog Height " << S1[5] << endl;
}
}
WAITKEY;
cls();
// Control Information
for( auto it : Linesvec)
{
rc= re[2]->FullMatch( it, &S1[0], &S1[1], &S1[2], &S1[3], &S1[4], &S1[5], &S1[6], &S1[7], &S1[8], &S1[9]);
if(rc )
{
cout << "----------------------------------" << endl;
cout << "Control Information" << endl;
cout << "----------------------------------" << endl;
cout << "Id: " << S1[1] << endl;
cout << "Text: " << S1[0] << endl;
cout << "Class: " << S1[2] << endl;
cout << "Style: " << S1[3] << endl;
cout << "Left: " << S1[4] << endl;
cout << "Top: " << S1[5] << endl;
cout << "Width: " << S1[6] << endl;
cout << "Height: " << S1[7] << endl;
if(S1[9].length())
{
cout << "Exe Style: " << S1[9] << endl;
}
WAITKEY;
cls();
}
}
for(i=0; i<=2; i+=1)
{
delete re[i];
}
return 0;
}