Code to change text format in text file

Hi,

Is there someone who could help me with this issue.

I have several hundred c++ code lines in a text file in this format:

IOCP.sendVarData(number, (int)sPmdgData.MCP_name);

The differences between all code lines are the number and and the name, the rest of the text is equal

What I need is to change these code lines to have the following format

if ((int)sPmdgData.MCP_name != T7X_MCP_name)
{
T7X_MCP_name = sPmdgData.MCP_name;
IOCP.sendVarData(number, T7X_MCP_name);
}

example:

from this format

IOCP.sendVarData(1374, (int)sPmdgData.MCP_FPA);

to this format

if ((int)sPmdgData.MCP_FPA != T7X_MCP_FPA)
{
T7X_MCP_FPA = sPmdgData.MCP_FPA;
IOCP.sendVarData(1374, T7X_MCP_FPA);
}


What I am looking for is c++ code to convert all my code lines in one run from the first format to the second format

Doing this manually for 600 code lines seems a waste of time.


regards,

roarkr
It looks like job for regex.
https://regex101.com/r/mG6lV8/1
(Maybe need to add more optional spaces to guard against any problems)
Edit: I beleve, this will allow spaces anywhere where they are allowed in C++
https://regex101.com/r/mG6lV8/2

You can achieve same in C++ using std::regex, but any program allowing you to use regexes to replace text will work just as good.
Last edited on
Create a new function:
1
2
3
4
5
6
7
8
sendVarNoDupe(int number, sometype name) // sometype is the type for sPmdgData.MCP_name
{
    if ((int) name!= T7X_MCP_name)
    {
        T7X_MCP_name = name;
        IOCP.sendVarData(number, T7X_MCP_name);
    }
}


Then change your code to
sendVarNoDupe(number, sPmdgData.MCP_name); using find/replace
I have several hundred c++ code lines in a text file in this format:

You didn't say whether the lines are all contiguous. If they are, then create a vector or array containing all the data, then use a loop to call the function. This will make it easier to make changes in the future, and the code will be a lot smaller.

Your code will not work.
Say how this is going to work? if ((int) name!= T7X_MCP_name)
MiiNiPaa,

The code works, do not bother with that.

Using regex in NotePad ++ seems to work Ok with given example, but it dosn't work with all name formats.
Looking more in detail how the names can be, this is correct

IOCP.sendVarData(number, (int)sPmdgData.name);

changed to:

if ((int)sPmdgData.name != T7X_name)
{
T7X_name = sPmdgData.name;
IOCP.sendVarData(number, T7X_name);
}

examples of name
MCP_RangeTFC_Sw_Pushed[1]
MCP_IAS_MACH_Toggle_Sw_Pushed
LTS_RunwayTurnoff_Sw_ON[0]

in other words, the name can be anything
Last edited on
examples of name
MCP_RangeTFC_Sw_Pushed[1]
MCP_IAS_MACH_Toggle_Sw_Pushed
LTS_RunwayTurnoff_Sw_ON[0]

I hope these are all integral values and not strings or something. I suspect that MiiNiPaa's comment was pointing out that the otherwise, a C-style cast won't do what you probably want.
Hi,

I believe I figured it out. I will give the the correct regex after some more testing
Hi Roarkr,

I am very interested by your IOCP C++ code to read/write SIOC variables from a C++ program. After long searchs through the web, I have not find an IOCP client based on the SIOC protocol.

Any help to find the source including the IOCP.sendVarData method will be highly apreciated !

Thank You,
Update,

Hi Roarkr,

I have downloaded a light IOCP client using winsock. From this code and some inormations about IOCP protocol applied to SIOC, I am writing my own c++ class to manage SIOC variables from a c++ program. My first results are very positive. I am experimenting delay times for executing SIOC commands impresively shorter than those required by FSUIPC !

Happy landings to all !
Topic archived. No new replies allowed.