Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: ollydbg on August 27, 2012, 09:17:24 am

Title: wxsmith code generate tab or spaces issue
Post by: ollydbg on August 27, 2012, 09:17:24 am
Firstly, I do not familiar with wxsmith's source code, but I do see an issue:

Code
wxString wxsCoder::RebuildCode(wxString& BaseIndentation,const wxChar* Code,int CodeLen,wxString& EOL)
{
    wxString Tab;
    bool UseTab = Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/use_tab"), false);
    int TabSize = Manager::Get()->GetConfigManager(_T("editor"))->ReadInt(_T("/tab_size"), 4);
    if ( !UseTab )
    {
        Tab.Append(_T(' '),TabSize);
    }

    if ( EOL.IsEmpty() )
    {
        int EolMode = Manager::Get()->GetConfigManager(_T("editor"))->ReadInt(_T("/eol/eolmode"), 0);
        switch ( EolMode )
        {
            case 1:  EOL = _T("\r"); break;
            case 2:  EOL = _T("\n"); break;
            default: EOL = _T("\r\n");
        }
    }

    BaseIndentation.Prepend(EOL);

    wxString Result;
    Result.reserve(CodeLen+10);

    while ( *Code )
    {
        switch ( *Code )
        {
            case _T('\n'):
                {
                    while (Result.Last() == _T(' ') || Result.Last() == _T('\t'))
                        Result.RemoveLast();
                    Result << BaseIndentation;
                    break;
                }
            case _T('\t'): if ( UseTab ) { Result << Tab; break; }
            default:       Result << *Code;
        }
        Code++;
    }

    return Result;
}

The Value "Tab" is either "empty string" or "four spaces".
There is something wrong with the line:
Code
case _T('\t'): if ( UseTab ) { Result << Tab; break; }

I think it should be:
Code
case _T('\t'): if ( !UseTab ) { Result << Tab; break; }

Otherwise, the '\t' is always added to the code, right?
Title: Re: wxsmith code generate tab or spaces issue
Post by: oBFusCATed on August 27, 2012, 09:33:35 am
And what is the test case to reproduce the problem?
Title: Re: wxsmith code generate tab or spaces issue
Post by: ollydbg on August 27, 2012, 09:59:24 am
And what is the test case to reproduce the problem?
There is an option: Configure Eidtor->General setting->Use Tab chars.
Whenever you select this option or not, the generate xrc/wxs file always use "Tabs". I would like use "4 spaces" in the xrc/wxs file, but I can't find a way.

I suspect the source code above cause the problem(I'm going to debug the code myself), I think the wxsmith should follow those options, but in-fact, it was not.

EDIT:
The code snippet in my original post was related to generate the source in h/cpp files, they are not related to code generation for xrc/wxs. but what the logic seems still wrong. :)