Author Topic: wxsmith generate inconsistent EOL  (Read 2841 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5251
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
wxsmith generate inconsistent EOL
« on: June 11, 2014, 02:43:25 pm »
See this screen shot below

I just use the wizard to create a wxWidgtes 3.0 simple project (C::B revision 9781, WinXP)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6761
    • My Best Post
Re: wxsmith generate inconsistent EOL
« Reply #1 on: June 11, 2014, 03:37:07 pm »
The line that I guess causes the problem.

From src\plugins\scriptedwizard\resources\wxwidgets\wizard.script
Code: [Select]
local PchInclude = WantPCH ? ( _T("#include \"") + PCHFileName + _T("\"\n") ) : _T("");

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5251
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: wxsmith generate inconsistent EOL
« Reply #2 on: June 11, 2014, 04:25:56 pm »
Hi, Tim, thanks.
Now, we have such code:
Code: [Select]
// -----------------------------------------------------------------------------
// substitute all plugin macros in <buffer>
function SubstituteMacros(buffer)
{
    // handle [IF] / [ENDIF] pairs
    if (GuiBuilder == 0)
    {
        if (GuiAppType == 0)
        {
            buffer  = HandleDirective(buffer, _T("WXDIALOG"), true);
            buffer  = HandleDirective(buffer, _T("WXFRAME"), false);
        }
        else if (GuiAppType == 1)
        {
            buffer  = HandleDirective(buffer, _T("WXDIALOG"), false);
            buffer  = HandleDirective(buffer, _T("WXFRAME"), true);
        }
        buffer  = HandleDirective(buffer, _T("NONE"), true);
        buffer  = HandleDirective(buffer, _T("WXFB"), false);
    }
    else if (GuiBuilder == 1)
    {
        if (GuiAppType == 0)
        {
            buffer  = HandleDirective(buffer, _T("WXDIALOG"), true);
            buffer  = HandleDirective(buffer, _T("WXFRAME"), false);
        }
        else if (GuiAppType == 1)
        {
            buffer  = HandleDirective(buffer, _T("WXDIALOG"), false);
            buffer  = HandleDirective(buffer, _T("WXFRAME"), true);
        }
    }
    else if (GuiBuilder == 2)
    {
        if (GuiAppType == 0)
        {
            buffer  = HandleDirective(buffer, _T("WXDIALOG"), true);
            buffer  = HandleDirective(buffer, _T("WXFRAME"), false);
        }
        else if (GuiAppType == 1)
        {
            buffer  = HandleDirective(buffer, _T("WXDIALOG"), false);
            buffer  = HandleDirective(buffer, _T("WXFRAME"), true);
        }
        buffer  = HandleDirective(buffer, _T("NONE"), false);
        buffer  = HandleDirective(buffer, _T("WXFB"), true);
    }
    buffer = HandleDirective(buffer, _T("WINDOWS"), (PLATFORM == PLATFORM_MSW ? true : false));

    // create class name from project name which is valid c++ identifier
    local Prefix = GetFixedProjectName(Wizard.GetProjectName());
    local PchInclude = WantPCH ? ( _T("#include \"") + PCHFileName + _T("\"\n") ) : _T("");

    // macros substitution
    buffer.Replace(_T("[PROJECT_HDR]"), Prefix.Upper() );
    buffer.Replace(_T("[PROJECT_NAME]"), Wizard.GetProjectName());
    buffer.Replace(_T("[FILENAME_PREFIX]"), Prefix);
    buffer.Replace(_T("[CLASS_PREFIX]"), Prefix);
    buffer.Replace(_T("[AUTHOR_NAME]"), ProjAuthor);
    buffer.Replace(_T("[AUTHOR_EMAIL]"), ProjEmail);
    buffer.Replace(_T("[AUTHOR_WWW]"), ProjWebsite);
    buffer.Replace(_T("[NOW]"), ReplaceMacros(_T("$(TODAY)"), false));
    buffer.Replace(_T("[PCH_INCLUDE]"), PchInclude);

    return buffer;
}

The PCH_INCLUDE will be replaced either by empty string or a #include statement with \n as the EOL.

The whole buffer is a template source file, such as Main.cpp
Code: [Select]
/***************************************************************
 * Name:      [FILENAME_PREFIX]Main.cpp
 * Purpose:   Code for Application Frame
 * Author:    [AUTHOR_NAME] ([AUTHOR_EMAIL])
 * Created:   [NOW]
 * Copyright: [AUTHOR_NAME] ([AUTHOR_WWW])
 * License:
 **************************************************************/

[PCH_INCLUDE]#include "[FILENAME_PREFIX]Main.h"
#include <wx/msgdlg.h>

//(*InternalHeaders([CLASS_PREFIX][IF WXFRAME]Frame[ENDIF WXFRAME][IF WXDIALOG]Dialog[ENDIF WXDIALOG])
//*)

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

The file under my system has CRLF.

So, what is the solution? Do we have any way to determine the EOL of the template file?
Another method is the use the EOL which is depend on the operation system, we already have some conditions in the script like:
Code: [Select]
if (PLATFORM != PLATFORM_MSW)
...
else
...
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6761
    • My Best Post
Re: wxsmith generate inconsistent EOL
« Reply #3 on: June 11, 2014, 05:21:20 pm »
I would suggest using "GetEOLStr(stc->GetEOLMode())"; but, I am not sure it is the correct function.
And, I am not sure how to get it used in a script file.

Looks like "GetEOLStr(-1)" should work easier than "GetEOLStr(stc->GetEOLMode())".

Tim S.
« Last Edit: June 11, 2014, 05:28:26 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org