Added logic to create the indenter calling script

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
master
Michele Calgaro 1 year ago
parent 97a6a7874e
commit 48a09796d5
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -31,6 +31,7 @@ set( ${target}_SRCS
ToolBarWidget.ui ToolBarWidget.ui
SettingsPaths.cpp SettingsPaths.cpp
TemplateBatchScript.cpp
UiGuiErrorMessage.cpp UiGuiErrorMessage.cpp
UiGuiIniFileParser.cpp UiGuiIniFileParser.cpp
UiGuiVersion.cpp UiGuiVersion.cpp

@ -20,12 +20,14 @@
#include "config.h" #include "config.h"
#include "IndentHandler.h" #include "IndentHandler.h"
#include <cstdlib>
#include "MainWindow.h" #include "MainWindow.h"
#include "SettingsPaths.h" #include "SettingsPaths.h"
#include "UiGuiErrorMessage.h" #include "UiGuiErrorMessage.h"
#include "UiGuiIniFileParser.h" #include "UiGuiIniFileParser.h"
#include "UiGuiSettings.h" #include "UiGuiSettings.h"
//--- #include "TemplateBatchScript.h" #include "TemplateBatchScript.h"
#include <tqapplication.h> #include <tqapplication.h>
#include <tqcheckbox.h> #include <tqcheckbox.h>
@ -215,94 +217,94 @@ void IndentHandler::contextMenuEvent(TQContextMenuEvent *event)
} }
} }
//--- /* /*
//--- \brief Creates the content for a shell script that can be used as a external tool call \brief Creates the content for a shell script that can be used as a external tool call
//--- to indent an as parameter defined file. to indent an as parameter defined file.
//--- */ */
//--- TQString IndentHandler::generateShellScript(const TQString &configFilename) TQString IndentHandler::generateShellScript(const TQString &configFilename)
//--- { {
//--- TQString indenterCompleteCallString; TQString indenterCompleteCallString;
//--- TQString parameterInputFile; TQString parameterInputFile;
//--- TQString parameterOuputFile; TQString parameterOuputFile;
//--- TQString parameterParameterFile; TQString parameterParameterFile;
//--- TQString replaceInputFileCommand; TQString replaceInputFileCommand;
//---
//--- // Define the placeholder for parameter variables either in batch or bash programming. // Define the placeholder for parameter variables either in batch or bash programming.
//--- TQString shellParameterPlaceholder = "$1"; TQString shellParameterPlaceholder = "$1";
//---
//--- parameterInputFile = " " + m_inputFileParameter + "\"" + shellParameterPlaceholder + "\""; parameterInputFile = " " + m_inputFileParameter + "\"" + shellParameterPlaceholder + "\"";
//---
//--- if (m_outputFileParameter != "none" && m_outputFileParameter != "stdout") if (m_outputFileParameter != "none" && m_outputFileParameter != "stdout")
//--- { {
//--- if (m_outputFileName == m_inputFileName) if (m_outputFileName == m_inputFileName)
//--- { {
//--- parameterOuputFile = " " + m_outputFileParameter + "\"" + shellParameterPlaceholder + "\""; parameterOuputFile = " " + m_outputFileParameter + "\"" + shellParameterPlaceholder + "\"";
//--- } }
//--- else else
//--- { {
//--- parameterOuputFile = " " + m_outputFileParameter + m_outputFileName + ".tmp"; parameterOuputFile = " " + m_outputFileParameter + m_outputFileName + ".tmp";
//--- } }
//--- } }
//---
//--- // If the config file name is empty it is assumed that all parameters are sent via command line // If the config file name is empty it is assumed that all parameters are sent via command line
//--- // call // call
//--- if (m_globalConfigFilename.isEmpty()) if (m_globalConfigFilename.isEmpty())
//--- { {
//--- parameterParameterFile = " " + getParameterString(); parameterParameterFile = " " + getParameterString();
//--- } }
//--- // else if needed add the parameter to the indenter call string where the config file can be // else if needed add the parameter to the indenter call string where the config file can be
//--- // found. // found.
//--- else if (m_useCfgFileParameter != "none") else if (m_useCfgFileParameter != "none")
//--- { {
//--- parameterParameterFile = " " + m_useCfgFileParameter + "\"./" + configFilename + "\""; parameterParameterFile = " " + m_useCfgFileParameter + "\"./" + configFilename + "\"";
//--- } }
//---
//--- // Assemble indenter call string for parameters according to the set order. // Assemble indenter call string for parameters according to the set order.
//--- if (m_parameterOrder == "ipo") if (m_parameterOrder == "ipo")
//--- { {
//--- indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile; indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile;
//--- } }
//--- else if (m_parameterOrder == "pio") else if (m_parameterOrder == "pio")
//--- { {
//--- indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile; indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile;
//--- } }
//--- else if (m_parameterOrder == "poi") else if (m_parameterOrder == "poi")
//--- { {
//--- indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile; indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile;
//--- } }
//--- else else
//--- { {
//--- indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile; indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile;
//--- } }
//---
//--- // Generate the indenter call string either for win32 or other systems. // Generate the indenter call string either for win32 or other systems.
//--- indenterCompleteCallString = "#!/bin/bash\n" + m_indenterExecutableCallString + indenterCompleteCallString = "#!/bin/bash\n" + m_indenterExecutableCallString +
//--- indenterCompleteCallString; indenterCompleteCallString;
//---
//--- // If the indenter writes to stdout pipe the output into a file // If the indenter writes to stdout pipe the output into a file
//--- if (m_outputFileParameter == "stdout") if (m_outputFileParameter == "stdout")
//--- { {
//--- indenterCompleteCallString = indenterCompleteCallString + " >" + m_outputFileName + ".tmp"; indenterCompleteCallString = indenterCompleteCallString + " >" + m_outputFileName + ".tmp";
//--- } }
//---
//--- // If the output filename is not the same as the input filename copy the output over the input. // If the output filename is not the same as the input filename copy the output over the input.
//--- if (m_outputFileName != m_inputFileName) if (m_outputFileName != m_inputFileName)
//--- { {
//--- replaceInputFileCommand = "mv " + m_outputFileName + ".tmp \"" + shellParameterPlaceholder + replaceInputFileCommand = "mv " + m_outputFileName + ".tmp \"" + shellParameterPlaceholder +
//--- "\"\n"; "\"\n";
//--- } }
//---
//--- TQString shellScript(TemplateBatchScript::getTemplateBatchScript()); TQString shellScript(TemplateBatchScript::getTemplateBatchScript());
//--- shellScript = shellScript.replace("__INDENTERCALLSTRING2__", shellScript = shellScript.replace("__INDENTERCALLSTRING2__",
//--- indenterCompleteCallString + "\n" + replaceInputFileCommand); indenterCompleteCallString + "\n" + replaceInputFileCommand);
//--- indenterCompleteCallString = indenterCompleteCallString.replace("$1", "$file2indent"); indenterCompleteCallString = indenterCompleteCallString.replace("$1", "$file2indent");
//--- replaceInputFileCommand = replaceInputFileCommand.replace("$1", "$file2indent"); replaceInputFileCommand = replaceInputFileCommand.replace("$1", "$file2indent");
//--- shellScript = shellScript.replace("__INDENTERCALLSTRING1__", shellScript = shellScript.replace("__INDENTERCALLSTRING1__",
//--- indenterCompleteCallString + "\n" + replaceInputFileCommand); indenterCompleteCallString + "\n" + replaceInputFileCommand);
//---
//--- return shellScript; return shellScript;
//--- } }
//---
//--- /* //--- /*
//--- \brief Format \a sourceCode by calling the indenter. //--- \brief Format \a sourceCode by calling the indenter.
//--- //---
@ -669,12 +671,13 @@ TQString IndentHandler::getParameterString()
*/ */
void IndentHandler::saveConfigFile(const TQString &filePathName, const TQString &paramString) void IndentHandler::saveConfigFile(const TQString &filePathName, const TQString &paramString)
{ {
//--- TQFile::remove(filePathName); TQFile::remove(filePathName);
//--- TQFile cfgFile(filePathName); TQFile cfgFile(filePathName);
//---
//--- cfgFile.open(TQFile::ReadWrite | TQFile::Text); cfgFile.open(IO_ReadWrite | IO_Translate);
//--- cfgFile.write(paramString.toAscii()); TQCString paramCString = paramString.local8Bit();
//--- cfgFile.close(); cfgFile.writeBlock(paramCString.data(), paramCString.length());
cfgFile.close();
} }
/* /*
@ -1548,22 +1551,22 @@ void IndentHandler::showIndenterManual() const
//--- TQDesktopServices::openUrl(manualReference); //--- TQDesktopServices::openUrl(manualReference);
} }
//--- /* /*
//--- \brief Returns the name of the currently selected indenter. \brief Returns the name of the currently selected indenter.
//--- */ */
//--- TQString IndentHandler::getCurrentIndenterName() TQString IndentHandler::getCurrentIndenterName()
//--- { {
//--- TQString currentIndenterName = m_indenterSelectionCombobox->currentText(); TQString currentIndenterName = m_indenterSelectionCombobox->currentText();
//---
//--- // Remove the supported programming languages from indenters name, which are set in braces. // Remove the supported programming languages from indenters name, which are set in braces.
//--- if (currentIndenterName.find("(") > 0) if (currentIndenterName.find("(") > 0)
//--- { {
//--- // Using index-1 to also leave out the blank before the brace. // Using index-1 to also leave out the blank before the brace.
//--- currentIndenterName = currentIndenterName.left(currentIndenterName.find("(") - 1); currentIndenterName = currentIndenterName.left(currentIndenterName.find("(") - 1);
//--- } }
//---
//--- return currentIndenterName; return currentIndenterName;
//--- } }
/* /*
\brief Shows a file open dialog to open an existing config file for the current indenter. \brief Shows a file open dialog to open an existing config file for the current indenter.
@ -1612,55 +1615,54 @@ void IndentHandler::saveasIndentCfgFileDialog()
*/ */
void IndentHandler::createIndenterCallShellScript() void IndentHandler::createIndenterCallShellScript()
{ {
//--- TQString shellScriptExtension; TQString shellScriptExtension;
//--- shellScriptExtension = "sh"; shellScriptExtension = "sh";
//---
//--- TQString fileExtensions = tr("Shell Script") + " (*." + shellScriptExtension + ");;" + tr( TQString fileExtensions = tr("Shell Script") + " (*." + shellScriptExtension + ");;" + tr(
//--- "All files") + " (*.*)"; "All files") + " (*.*)";
//---
//--- TQString currentIndenterName = getCurrentIndenterName(); TQString currentIndenterName = getCurrentIndenterName();
//--- currentIndenterName = currentIndenterName.replace(" ", "_"); currentIndenterName = currentIndenterName.replace(" ", "_");
//---
//--- TQString shellScriptFileName = TQFileDialog::getSaveFileName(this, tr( TQString indenterScriptName = "call_" + currentIndenterName + "." + shellScriptExtension;
//--- "Save shell script"), "call_" + currentIndenterName + "." + shellScriptExtension, TQString shellScriptFileName = TQFileDialog::getSaveFileName(indenterScriptName,
//--- fileExtensions); fileExtensions, nullptr, nullptr, tr("Save shell script"));
//---
//--- // Saving has been canceled if the filename is empty // Saving has been canceled if the filename is empty
//--- if (shellScriptFileName.isEmpty()) if (shellScriptFileName.isEmpty())
//--- { {
//--- return; return;
//--- } }
//---
//--- // Delete any old file, write the new contents and set executable permissions. // Delete any old file, write the new contents and set executable permissions.
//--- TQFile::remove(shellScriptFileName); TQFile::remove(shellScriptFileName);
//--- TQFile outSrcFile(shellScriptFileName); TQFile outSrcFile(shellScriptFileName);
//--- if (outSrcFile.open(TQFile::ReadWrite | TQFile::Text)) if (outSrcFile.open(IO_ReadWrite | IO_Translate))
//--- { {
//--- TQString shellScriptConfigFilename = TQFileInfo(shellScriptFileName).baseName() + "." + TQString shellScriptConfigFilename = TQFileInfo(shellScriptFileName).baseName() + "." +
//--- TQFileInfo(m_globalConfigFilename).suffix(); TQFileInfo(m_globalConfigFilename).extension(false);
//---
//--- // Get the content of the shell/batch script. // Get the content of the shell/batch script.
//--- TQString indenterCallShellScript = generateShellScript(shellScriptConfigFilename); TQString indenterCallShellScript = generateShellScript(shellScriptConfigFilename);
//---
//--- // Replace placeholder for script name in script template. // Replace placeholder for script name in script template.
//--- indenterCallShellScript = indenterCallShellScript.replace("__INDENTERCALLSTRINGSCRIPTNAME__", TQFileInfo( indenterCallShellScript = indenterCallShellScript.replace("__INDENTERCALLSTRINGSCRIPTNAME__",
//--- shellScriptFileName).fileName()); TQFileInfo(shellScriptFileName).fileName());
//---
//--- outSrcFile.write(indenterCallShellScript.toAscii()); TQCString indenterString = indenterCallShellScript.local8Bit();
//--- // For non Windows systems set the files executable flag outSrcFile.writeBlock(indenterString.data(), indenterString.length());
//--- outSrcFile.setPermissions( // For non Windows systems set the files executable flag
//--- outSrcFile.permissions() | TQFile::ExeOwner | TQFile::ExeUser | TQFile::ExeGroup); outSrcFile.close();
//--- outSrcFile.close(); int _ = std::system("chmod a+x " + shellScriptFileName.local8Bit());
//---
//--- // Save the indenter config file to the same directory, where the shell srcipt was saved to, // Save the indenter config file to the same directory, where the shell srcipt was saved to,
//--- // because the script will reference it there via "./". // because the script will reference it there via "./".
//--- if (!m_globalConfigFilename.isEmpty()) if (!m_globalConfigFilename.isEmpty())
//--- { {
//--- saveConfigFile(TQFileInfo( saveConfigFile(TQFileInfo(shellScriptFileName).dirPath(true) + "/" + shellScriptConfigFilename,
//--- shellScriptFileName).path() + "/" + shellScriptConfigFilename, getParameterString());
//--- getParameterString()); }
//--- } }
//--- }
} }
/* /*

@ -46,7 +46,7 @@ class IndentHandler : public TQWidget
IndentHandler(int indenterID, MainWindow *mainWindow = nullptr, TQWidget *parent = nullptr); IndentHandler(int indenterID, MainWindow *mainWindow = nullptr, TQWidget *parent = nullptr);
~IndentHandler(); ~IndentHandler();
///-- TQString generateShellScript(const TQString &configFilename); TQString generateShellScript(const TQString &configFilename);
///-- TQString callIndenter(TQString sourceCode, TQString inputFileExtension); ///-- TQString callIndenter(TQString sourceCode, TQString inputFileExtension);
bool loadConfigFile(const TQString &filePathName); bool loadConfigFile(const TQString &filePathName);
void resetToDefaultValues(); void resetToDefaultValues();
@ -55,7 +55,7 @@ class IndentHandler : public TQWidget
TQString getParameterString(); TQString getParameterString();
TQString getIndenterCfgFile(); TQString getIndenterCfgFile();
///-- TQString getManual(); ///-- TQString getManual();
///-- TQString getCurrentIndenterName(); TQString getCurrentIndenterName();
void contextMenuEvent(TQContextMenuEvent *event); void contextMenuEvent(TQContextMenuEvent *event);
signals: signals:

@ -20,7 +20,7 @@
#include "TemplateBatchScript.h" #include "TemplateBatchScript.h"
/* /*
\brief The only and static function of this class returns a batch or shell script \brief The only static function of this class returns a batch or shell script
as string that can be used to call an indenter with the current settings from as string that can be used to call an indenter with the current settings from
the command line. the command line.

@ -29,4 +29,4 @@ class TemplateBatchScript
static const char* getTemplateBatchScript(); static const char* getTemplateBatchScript();
}; };
#endif // TEMPLATEBATCHSCRIPT_H #endif
Loading…
Cancel
Save