コード例 #1
0
char* AStyleFormat::CallAStyleMain(const char* textIn, const char* options) const
{
#ifdef ASTYLE_DYLIB
	// format using dll dynamic load
	if (fpAStyleMain == nullptr)	// cannot use aslib.IsLoaded() after Detach()
	{
		ShowMessageDialog(wxString::Format(
		                      "Error calling the function AStyleMain.\n"
		                      "The AStyle library %s is not loaded.\n"
		                      "The text cannot be formatted.\n"
		                      "This must be corrected to format the text!",
		                      GetDynamicLibraryName().c_str()),
		                  wxOK | wxICON_ERROR);
		return nullptr;
	}

	char* textOut = fpAStyleMain(textIn,
	                             options,
	                             ErrorHandler,
	                             MemoryAlloc);
#else
	// format using static library
	char* textOut = AStyleMain(textIn,
	                           options,
	                           ErrorHandler,
	                           MemoryAlloc);
#endif	// ASTYLE_DYLIB
	return textOut;
}
コード例 #2
0
/**
* Call the AStyleMain function in Artistic Style.
*
* @param   textIn  A pointer to the source code to be formatted.
* @return  A pointer to the formatted source from Artistic Style.
*/
char* AStyleInterface::formatSource(const char* textIn, const char* options)
{  
    char* textOut = AStyleMain(textIn,
                               options,
                               errorHandler,
                               memoryAlloc);
    return textOut;
}
コード例 #3
0
ファイル: codeformatter.cpp プロジェクト: 292388900/codelite
void CodeFormatter::AstyleFormat(const wxString& input, const wxString& options, wxString& output)
{
    char* textOut = AStyleMain(_C(input), _C(options), ASErrorHandler, ASMemoryAlloc);
    if(textOut) {
        output = _U(textOut);
        output.Trim();
        delete[] textOut;
    }
}
コード例 #4
0
/**
* Call the AStyleMain function in Artistic Style.
*
* @param   textIn  A pointer to the source code to be formatted.
* @return  A pointer to the formatted source from Artistic Style.
*/
char* AStyleInterface::formatSource(const char* textIn)
{   string options = getOptions();
    //displayErrorMessage("--------------------");
    //displayErrorMessage(options);
    //displayErrorMessage("--------------------");
    char* textOut = AStyleMain(textIn,
                               options.c_str(),
                               errorHandler,
                               memoryAlloc);
    return textOut;
}
コード例 #5
0
ファイル: CFCppTidy.cpp プロジェクト: TinyCoolFormat/alpha
bool CCFCppTidy::TidyMain(const char* pSourceIn, const char *pOptions, std::string &strOut, std::string &strErr)
{
    s_strErr.clear();

    char* textOut = AStyleMain(pSourceIn, pOptions,
                               ASErrorHandler,
                               ASMemoryAlloc);

    strErr = s_strErr;
    if (textOut == NULL)
    {
        return false;
    }

    strOut = textOut;
    delete[] textOut;
    return true;
}
コード例 #6
0
ファイル: astyle_wrapper.cpp プロジェクト: Ruzzz/AStyle
bool astyle(std::string &content, const char *options)
{
    // allocate internal buffer
    size_t len = content.size();
    char *textIn = new(std::nothrow) char[len + 1];
    if (!textIn)
        return false;
    // copy to internal buffer
#ifdef WIN32
#pragma warning(push)  // FIX
#pragma warning(disable: 4996)
    size_t copied = content.copy(textIn, len);
#pragma warning(pop)
#else
    size_t copied = content.copy(textIn, len);
#endif
	if (copied != len)
    {
        delete[] textIn;
        return false;
    }
    textIn[len] = '\0';
    // call astyle
    error = false;
    char *textOut = AStyleMain(textIn, options, handleError, allocMemory);
    delete[] textIn;
    // check error
    if (error)
    {
        if (textOut)
            delete[] textOut;
        return false;
    }
    if (!textOut)
        return false;
    // return result
    std::string result(textOut, strlen(textOut));
	delete[] textOut;
    content.swap(result);
	return true;
}