34 #include "scripting/sqplus/sqplus.h" 41 template<>
MacrosManager* Mgr<MacrosManager>::instance =
nullptr;
70 ReplaceMacros(tmp, target);
76 m_LastProject =
nullptr;
77 m_LastTarget =
nullptr;
79 m_ActiveEditorLine = -1;
80 m_ActiveEditorColumn = -1;
91 m_RE_ToAbsolutePath.Compile(
_T(
"\\$TO_ABSOLUTE_PATH{([^}]*)}"),
97 m_RE_To83Path.Compile(
_T(
"\\$TO_83_PATH{([^}]*)}"),
103 m_RE_RemoveQuotes.Compile(
_T(
"\\$REMOVE_QUOTES{([^}]*)}"),
110 srand(time(
nullptr));
111 assert(m_RE_Unix.IsValid());
112 assert(m_RE_DOS.IsValid());
119 m_Macros[
_T(
"AMP")] =
_T(
"&");
120 m_Macros[
_T(
"CODEBLOCKS")] = m_AppPath;
121 m_Macros[
_T(
"APP_PATH")] = m_AppPath;
122 m_Macros[
_T(
"APP-PATH")] = m_AppPath;
123 m_Macros[
_T(
"APPPATH")] = m_AppPath;
124 m_Macros[
_T(
"DATA_PATH")] = m_DataPath;
125 m_Macros[
_T(
"DATA-PATH")] = m_DataPath;
126 m_Macros[
_T(
"DATAPATH")] = m_DataPath;
127 m_Macros[
_T(
"PLUGINS")] = m_Plugins;
131 if (platform::windows)
133 m_Macros[
_T(
"CMD_NULL")] =
_T(
"NUL");
136 m_Macros[
_T(
"CMD_CP")] = cmd +
_T(
"copy");
137 m_Macros[_T(
"CMD_RM")] = cmd + _T(
"del");
138 m_Macros[_T(
"CMD_MV")] = cmd + _T(
"move");
139 m_Macros[_T(
"CMD_MKDIR")] = cmd + _T(
"md");
140 m_Macros[_T(
"CMD_RMDIR")] = cmd + _T(
"rd");
144 m_Macros[
_T(
"CMD_CP")] =
_T(
"cp --preserve=timestamps");
145 m_Macros[
_T(
"CMD_RM")] =
_T(
"rm");
146 m_Macros[
_T(
"CMD_MV")] =
_T(
"mv");
147 m_Macros[
_T(
"CMD_NULL")] =
_T(
"/dev/null");
148 m_Macros[
_T(
"CMD_MKDIR")] =
_T(
"mkdir -p");
149 m_Macros[
_T(
"CMD_RMDIR")] =
_T(
"rmdir");
156 m_WorkspaceFilename =
UnixFilename(m_WorkspaceWxFileName.GetFullName());
158 m_WorkspaceDir =
UnixFilename(m_WorkspaceWxFileName.GetPath());
162 m_WorkspaceWxFileName.
Clear();
167 m_Macros[
_T(
"WORKSPACE_FILE")] = m_WorkspaceFilename;
168 m_Macros[
_T(
"WORKSPACE_FILENAME")] = m_WorkspaceFilename;
169 m_Macros[
_T(
"WORKSPACE_FILE_NAME")] = m_WorkspaceFilename;
170 m_Macros[
_T(
"WORKSPACEFILE")] = m_WorkspaceFilename;
171 m_Macros[
_T(
"WORKSPACEFILENAME")] = m_WorkspaceFilename;
172 m_Macros[
_T(
"WORKSPACENAME")] = m_WorkspaceName;
173 m_Macros[
_T(
"WORKSPACE_NAME")] = m_WorkspaceName;
174 m_Macros[
_T(
"WORKSPACE_DIR")] = m_WorkspaceDir;
175 m_Macros[
_T(
"WORKSPACE_DIRECTORY")] = m_WorkspaceDir;
176 m_Macros[
_T(
"WORKSPACEDIR")] = m_WorkspaceDir;
177 m_Macros[
_T(
"WORKSPACEDIRECTORY")] = m_WorkspaceDir;
206 void ReadMacros(MacrosMap ¯os, T *
object)
210 const StringHash& v =
object->GetAllVars();
211 for (StringHash::const_iterator it = v.begin(); it != v.end(); ++it)
212 macros[it->first.Upper()] = it->second;
220 m_ActiveEditorLine = -1;
221 m_ActiveEditorColumn = -1;
229 const StringHash& v = m_LastTarget->GetAllVars();
230 for (StringHash::const_iterator it = v.begin(); it != v.end(); ++it)
231 m_Macros.
erase(it->first.Upper());
238 if (editor->
GetFilename() != m_ActiveEditorFilename)
251 m_ActiveEditorColumn = cbSTC->
GetColumn(pos) + 1;
263 m_LastProject =
nullptr;
283 else if ( (project != m_LastProject) || (project->
GetTitle() != m_ProjectName)
285 || (
UnixFilename(m_ProjectWxFileName.GetFullName()) != m_ProjectFilename)
288 m_LastTarget =
nullptr;
289 m_ProjectWxFileName.Assign(project->
GetFilename());
290 m_ProjectFilename =
UnixFilename(m_ProjectWxFileName.GetFullName());
291 m_ProjectName = project->
GetTitle();
301 m_ProjectFiles << out <<
_T(
' ');
305 m_Macros[
_T(
"PROJECTFILE")] = m_ProjectFilename;
306 m_Macros[
_T(
"PROJECT_FILE")] = m_ProjectFilename;
307 m_Macros[
_T(
"PROJECTFILENAME")] = m_ProjectFilename;
308 m_Macros[
_T(
"PROJECT_FILENAME")] = m_ProjectFilename;
309 m_Macros[
_T(
"PROJECT_FILE_NAME")] = m_ProjectFilename;
310 m_Macros[
_T(
"PROJECTNAME")] = m_ProjectName;
311 m_Macros[
_T(
"PROJECT_NAME")] = m_ProjectName;
312 m_Macros[
_T(
"PROJECTDIR")] = m_ProjectDir;
313 m_Macros[
_T(
"PROJECT_DIR")] = m_ProjectDir;
314 m_Macros[
_T(
"PROJECTDIRECTORY")] = m_ProjectDir;
315 m_Macros[
_T(
"PROJECT_DIRECTORY")] = m_ProjectDir;
316 m_Macros[
_T(
"PROJECTTOPDIR")] = m_ProjectTopDir;
317 m_Macros[
_T(
"PROJECT_TOPDIR")] = m_ProjectTopDir;
318 m_Macros[
_T(
"PROJECTTOPDIRECTORY")] = m_ProjectTopDir;
319 m_Macros[
_T(
"PROJECT_TOPDIRECTORY")] = m_ProjectTopDir;
320 m_Macros[
_T(
"MAKEFILE")] = m_Makefile;
321 m_Macros[
_T(
"ALL_PROJECT_FILES")] = m_ProjectFiles;
336 m_LastProject = project;
343 ReadMacros(m_Macros, compiler);
346 ReadMacros(m_Macros, project);
355 m_LastTarget =
nullptr;
357 else if ( (target != m_LastTarget) or (target->
GetTitle() != m_TargetName) )
360 m_TargetOutputDir =
UnixFilename(tod.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
365 m_LastTarget = target;
370 ReadMacros(m_Macros, target);
374 m_Macros[
_T(
"TARGET_CC")] = c->GetPrograms().C;
375 m_Macros[
_T(
"TARGET_CPP")] = c->GetPrograms().CPP;
376 m_Macros[
_T(
"TARGET_LD")] = c->GetPrograms().LD;
377 m_Macros[
_T(
"TARGET_LIB")] = c->GetPrograms().LIB;
385 m_Macros[
_T(
"TARGET_OUTPUT_DIR")] = m_TargetOutputDir;
386 m_Macros[
_T(
"TARGET_NAME")] = m_TargetName;
387 m_Macros[
_T(
"TARGET_OUTPUT_BASENAME")] = m_TargetOutputBaseName;
388 m_Macros[
_T(
"TARGET_OUTPUT_FILENAME")] = m_TargetOutputFilename;
389 m_Macros[
_T(
"TARGET_OUTPUT_FILE")] = m_TargetFilename;
391 m_Macros[
_T(
"ACTIVE_EDITOR_FILENAME")] =
UnixFilename(m_ActiveEditorFilename);
393 m_Macros[
_T(
"ACTIVE_EDITOR_DIRNAME")] = fn.
GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
394 m_Macros[
_T(
"ACTIVE_EDITOR_STEM")] = fn.
GetName();
395 m_Macros[
_T(
"ACTIVE_EDITOR_EXT")] = fn.
GetExt();
398 temp_str.
Printf(
_T(
"%d"), m_ActiveEditorLine);
399 m_Macros[
_T(
"ACTIVE_EDITOR_LINE")] = temp_str;
400 temp_str.
Printf(
_T(
"%d"), (m_ActiveEditorLine>0) ? m_ActiveEditorLine-1 : -1);
401 m_Macros[
_T(
"ACTIVE_EDITOR_LINE_0")] = temp_str;
402 temp_str.
Printf(
_T(
"%d"), m_ActiveEditorColumn);
403 m_Macros[
_T(
"ACTIVE_EDITOR_COLUMN")] = temp_str;
404 temp_str.
Printf(
_T(
"%d"), (m_ActiveEditorColumn>0) ? m_ActiveEditorColumn-1 : -1);
405 m_Macros[
_T(
"ACTIVE_EDITOR_COLUMN_0")] = temp_str;
428 m_Macros[
_T(
"TDAY")] = now.
Format(
_T(
"%Y%m%d"));
429 m_Macros[
_T(
"TODAY")] = now.
Format(
_T(
"%Y-%m-%d"));
430 m_Macros[
_T(
"NOW")] = now.
Format(
_T(
"%Y-%m-%d-%H.%M"));
431 m_Macros[
_T(
"NOW_L")] = now.
Format(
_T(
"%Y-%m-%d-%H.%M.%S"));
432 m_Macros[
_T(
"WEEKDAY")] = now.
Format(
_T(
"%A"));
435 m_Macros[
_T(
"TDAY_UTC")] = nowGMT.
Format(
_T(
"%Y%m%d"));
436 m_Macros[
_T(
"TODAY_UTC")] = nowGMT.
Format(
_T(
"%Y-%m-%d"));
437 m_Macros[
_T(
"NOW_UTC")] = nowGMT.
Format(
_T(
"%Y-%m-%d-%H.%M"));
438 m_Macros[
_T(
"NOW_L_UTC")] = nowGMT.
Format(
_T(
"%Y-%m-%d-%H.%M.%S"));
439 m_Macros[
_T(
"WEEKDAY_UTC")] = nowGMT.
Format(
_T(
"%A"));
472 if (project != m_LastProject || target != m_LastTarget || (editor && (editor->
GetFilename() != m_ActiveEditorFilename))
474 || (
UnixFilename(m_ProjectWxFileName.GetFullName()) != m_ProjectFilename)
475 || (target && (target->
GetTitle() != m_TargetName)) )
476 RecalcVars(project, editor, target);
483 while (m_RE_If.Matches(buffer))
485 search = m_RE_If.GetMatch(buffer, 0);
486 replace = EvalCondition(m_RE_If.GetMatch(buffer, 1), m_RE_If.GetMatch(buffer, 3), m_RE_If.GetMatch(buffer, 5), target);
487 buffer.
Replace(search, replace,
false);
491 while (m_RE_Script.Matches(buffer))
493 search = m_RE_Script.GetMatch(buffer, 1);
495 buffer.
Replace(search, replace,
false);
498 while (m_RE_ToAbsolutePath.Matches(buffer))
500 search = m_RE_ToAbsolutePath.GetMatch(buffer, 0);
501 const wxString relativePath = m_RE_ToAbsolutePath.GetMatch(buffer, 1);
505 buffer.
Replace(search, replace,
false);
508 while (m_RE_To83Path.Matches(buffer))
510 search = m_RE_To83Path.GetMatch(buffer, 0);
511 const wxString path = m_RE_To83Path.GetMatch(buffer, 1);
515 buffer.
Replace(search, replace,
false);
523 ReplaceMacros(content, target,
true);
531 ReplaceMacros(content, target,
true);
539 ReplaceMacros(content, target,
true);
543 while (m_RE_RemoveQuotes.Matches(buffer))
545 search = m_RE_RemoveQuotes.GetMatch(buffer, 0);
546 wxString content = m_RE_RemoveQuotes.GetMatch(buffer, 1).
Trim().
Trim(
false);
548 ReplaceMacros(content, target, subrequest);
551 replace = content.
Mid(1,content.
Len()-2);
552 buffer.
Replace(search, replace,
false);
555 buffer.
Replace(search, content,
false);
558 while (m_RE_Unix.Matches(buffer))
561 search = m_RE_Unix.GetMatch(buffer, 2);
570 replace.
assign(1u, rand() & 1 ?
_T(
'1') :
_T(
'0'));
575 MacrosMap::iterator it;
576 if ((it = m_Macros.find(var)) != m_Macros.end())
577 replace = it->second;
582 if (l ==
_T(
'/') || l ==
_T(
'\\') || l ==
_T(
'$') || l ==
_T(
' '))
588 buffer.
Replace(search, replace,
false);
591 while (m_RE_DOS.Matches(buffer))
594 search = m_RE_DOS.GetMatch(buffer, 2);
603 replace.
assign(1u, rand() & 1 ?
_T(
'1') :
_T(
'0'));
608 MacrosMap::iterator it;
609 if ((it = m_Macros.find(var)) != m_Macros.end())
610 replace = it->second;
617 buffer.
Replace(search, replace,
false);
629 enum condition_codes {EQ = 1,
LT = 2,
GT = 4, NE = 8};
634 ReplaceMacros(cond, target,
true);
636 if (!m_RE_IfSp.Matches(in_cond))
640 wxString cmpToken(m_RE_IfSp.GetMatch(in_cond, 3).Strip(wxString::both));
641 wxString left(m_RE_IfSp.GetMatch(in_cond, 2).Strip(wxString::both));
642 wxString right(m_RE_IfSp.GetMatch(in_cond, 4).Strip(wxString::both));
645 int compare = left.
Cmp(right);
648 else if (compare < 0)
650 else if (compare > 0)
654 if (cmpToken.IsEmpty())
663 if (cmpToken.IsSameAs(
_T(
"==")) || cmpToken.IsSameAs(
_T(
"=")))
665 if (cmpToken.IsSameAs(
_T(
"<")))
667 if (cmpToken.IsSameAs(
_T(
">")))
669 if (cmpToken.IsSameAs(
_T(
"<=")))
671 if (cmpToken.IsSameAs(
_T(
">=")))
673 if (cmpToken.IsSameAs(
_T(
"!=")))
676 return condCode & compare ? true_clause : false_clause;
682 while (index < (
int)buffer.
Length())
684 if (buffer[index] ==
wxT(
'{'))
686 else if (buffer[index] ==
wxT(
'}'))
static wxString GetLanguageName(int lang)
~MacrosManager() override
bool wxGetEnv(const wxString &var, wxString *value)
int WordEndPosition(int pos, bool onlyWordCharacters)
Get position of end of word.
int MatchBrace(const wxString &buffer, int index)
UserVariableManager * GetUserVariableManager() const
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
virtual const wxString & GetExecutionParameters() const
Read the target's execution parameters.
int Cmp(const wxString &s) const
virtual FilesList & GetFilesList()
Provides an easy way to iterate all the files belonging in this target.
wxString GetShortPath() const
int GetColumn(int pos) const
Retrieve the column number of a position, taking tab width into account.
static wxStandardPaths & Get()
static const wxString const_RANDOM(_T("RANDOM"))
virtual wxString GetFilename() const
Get the workspace file's name.
static Compiler * GetCompiler(size_t index)
wxString & append(const wxString &str, size_t pos, size_t n)
static const wxString toWindowsPath(_T("$TO_WINDOWS_PATH{"))
wxString EvalCondition(const wxString &cond, const wxString &true_clause, const wxString &false_clause, ProjectBuildTarget *target)
const wxString GT(_T(">"))
void SetPath(const wxString &path, wxPathFormat format=wxPATH_NATIVE)
Represents a file in a Code::Blocks project.
ProjectBuildTarget * GetCurrentlyCompilingTarget()
Get a pointer to the currently compiling target.
size_t find(const wxString &str, size_t nStart=0) const
virtual wxString GetOutputFilename()
Read the target's output filename.
virtual cbProject * GetParentProject()
int WordStartPosition(int pos, bool onlyWordCharacters)
Get position of start of word.
EditorManager * GetEditorManager() const
static const wxString toUnixPath(_T("$TO_UNIX_PATH{"))
wxUSE_UNICODE_dependent wxChar
wxString GetSelectedText()
Retrieve the selected text.
const wxString & GetMakefile()
ProjectManager * GetProjectManager() const
Functions returning pointers to the respective sub-manager instances.
wxDateTime Subtract(const wxTimeSpan &diff) const
virtual const wxString & GetFilename() const
Get the editor's filename (if applicable).
DLLIMPORT wxString UnixFilename(const wxString &filename, wxPathFormat format=wxPATH_NATIVE)
static int GetSystemLanguage()
Represents a Code::Blocks project.
const wxString & GetActiveBuildTarget() const
virtual const wxString & GetFilename() const
int GetCurrentLine()
Manually declared methods.
EditorBase * GetActiveEditor()
void RecalcVars(cbProject *project, EditorBase *editor, ProjectBuildTarget *target)
size_t find_first_of(const char *sz, size_t nStart=0) const
cbStyledTextCtrl * GetControl() const
Returns a pointer to the underlying cbStyledTextCtrl object (which itself is the wxWindows implementa...
virtual const wxString & GetTitle() const
Read the target's title.
static wxString GetSystemEncodingName()
static const wxString const_COIN(_T("COIN"))
size_t Replace(const wxString &strOld, const wxString &strNew, bool replaceAll=true)
wxString LoadBufferRedirectOutput(const wxString &buffer)
Loads a string buffer and captures its output.
cbEditor * GetBuiltinActiveEditor()
bool IsSameAs(const wxString &s, bool caseSensitive=true) const
wxString GetPathWithSep(wxPathFormat format=wxPATH_NATIVE) const
Base class that all "editors" should inherit from.
int GetCurrentPos() const
Returns the position of the caret.
cbProject * GetActiveProject()
Retrieve the active project.
virtual wxString GetBasePath() const
Read the target's base path, e.g. if GetFilename() returns "/usr/local/bin/xxx", base path will retur...
const wxString LT(_T("<"))
const wxStringCharType * wx_str() const
virtual bool IsBuiltinEditor() const
Is this a built-in editor?
wxString & assign(const wxString &str, size_t pos, size_t n)
int compare(const wxString &str) const
DLLIMPORT void QuoteStringIfNeeded(wxString &str)
wxString & Trim(bool fromRight=true)
void ReplaceMacros(wxString &buffer, ProjectBuildTarget *target=nullptr, bool subrequest=false)
int GetBuildTargetsCount()
static wxString GetDataFolder(bool global=true)
ProjectBuildTarget * GetBuildTarget(int index)
Access a build target.
cbWorkspace * GetWorkspace()
Get the current workspace filename.
Abstract base class for compilers.
wxString & erase(size_type pos=0, size_type n=npos)
wxString GetPath(int flags=wxPATH_GET_VOLUME, wxPathFormat format=wxPATH_NATIVE) const
virtual const wxString & GetCompilerID() const
Read the target's compiler.
static wxString GetExecutableFolder()
bool EndsWith(const wxString &suffix, wxString *rest=NULL) const
wxString GetCommonTopLevelPath() const
static wxString GetPluginsFolder(bool global=true)
bool StartsWith(const wxString &prefix, wxString *rest=NULL) const
static const wxString toNativePath(_T("$TO_NATIVE_PATH{"))
Represents a Code::Blocks project build target.
wxUniChar GetChar(size_t n) const
ScriptingManager * GetScriptingManager() const
bool MakeAbsolute(const wxString &cwd=wxEmptyString, wxPathFormat format=wxPATH_NATIVE)
int Printf(const wxString &pszFormat,...)
virtual wxString GetObjectOutput() const
Read the target's objects output dir.
wxString Format(const wxString &format=wxDefaultDateTimeFormat, const TimeZone &tz=Local) const
wxString GetFullPath(wxPathFormat format=wxPATH_NATIVE) const
virtual wxString GetTitle() const
Get the workspace's title.
static wxString Format(const wxString &format,...)
wxString Mid(size_t first, size_t nCount=wxString::npos) const
wxString GetSelectedText()