summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitri van Heesch <dimitri@stack.nl>2018-07-17 17:36:48 (GMT)
committerDimitri van Heesch <dimitri@stack.nl>2018-07-17 17:36:48 (GMT)
commitbd6c93b2d26a9a80df66a25404613e285ef35815 (patch)
treef42aaba921fadc8f63651ebe1b07c0e5265800b8
parenta05532d8532f5f71e1ae7ff4d383102ee91cd17c (diff)
downloadDoxygen-bd6c93b2d26a9a80df66a25404613e285ef35815.zip
Doxygen-bd6c93b2d26a9a80df66a25404613e285ef35815.tar.gz
Doxygen-bd6c93b2d26a9a80df66a25404613e285ef35815.tar.bz2
Added substitution variant for character substitution
-rw-r--r--src/portable.cpp32
-rw-r--r--src/util.cpp16
-rw-r--r--src/util.h1
3 files changed, 22 insertions, 27 deletions
diff --git a/src/portable.cpp b/src/portable.cpp
index 224266a..b4417c2 100644
--- a/src/portable.cpp
+++ b/src/portable.cpp
@@ -36,17 +36,8 @@ int portable_system(const char *command,const char *args,bool commandHasConsole)
if (command==0) return 1;
#if defined(_WIN32) && !defined(__CYGWIN__)
- const char *p = command;
- char *q = (char *)malloc(strlen(p) + 1);
- strcpy(q, p);
- for (int i = 0 ; i < strlen(q); i++)
- {
- if (q[i] == '/')
- {
- q[i] = '\\';
- }
- }
- QCString fullCmd=q;
+ QCString commandCorrectedPath = substitute(command,'/','\\');
+ QCString fullCmd=commandCorrectedPath;
#else
QCString fullCmd=command;
#endif
@@ -136,7 +127,6 @@ int portable_system(const char *command,const char *args,bool commandHasConsole)
#else // Win32 specific
if (commandHasConsole)
{
- free(q);
return system(fullCmd);
}
else
@@ -149,7 +139,7 @@ int portable_system(const char *command,const char *args,bool commandHasConsole)
// For that case COM is initialized as follows
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
- QString commandw = QString::fromUtf8( q );
+ QString commandw = QString::fromUtf8( commandCorrectedPath );
QString argsw = QString::fromUtf8( args );
// gswin32 is a GUI api which will pop up a window and run
@@ -176,7 +166,6 @@ int portable_system(const char *command,const char *args,bool commandHasConsole)
NULL, /* ignored: icon */
NULL /* resulting application handle */
};
- free(q);
if (!ShellExecuteExW(&sInfo))
{
@@ -474,18 +463,7 @@ void portable_correct_path(void)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
const char *p = portable_getenv("PATH");
- char *q = (char *)malloc(strlen(p) + 1);
- strcpy(q, p);
- bool found = false;
- for (int i = 0 ; i < strlen(q); i++)
- {
- if (q[i] == '/')
- {
- q[i] = '\\';
- found = true;
- }
- }
- if (found) portable_setenv("PATH",q);
- free(q);
+ QCString result = substitute(p,'/','\\');
+ if (result!=p) portable_setenv("PATH",result.data());
#endif
}
diff --git a/src/util.cpp b/src/util.cpp
index ea68cd7..581ecfc 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -5290,6 +5290,22 @@ QCString substitute(const QCString &s,const QCString &src,const QCString &dst,in
return result;
}
+/// substitute all occurrences of \a srcChar in \a s by \a dstChar
+QCString substitute(const QCString &s,char srcChar,char dstChar)
+{
+ int l=s.length();
+ QCString result(l+1);
+ char *q=result.rawData();
+ if (l>0)
+ {
+ const char *p=s.data();
+ char c;
+ while ((c=*p++)) *q++ = (c==srcChar) ? dstChar : c;
+ }
+ *q='\0';
+ return result;
+}
+
//----------------------------------------------------------------------
QCString substituteKeywords(const QCString &s,const char *title,
diff --git a/src/util.h b/src/util.h
index 7cbe5e3..18c329d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -194,6 +194,7 @@ QCString substituteClassNames(const QCString &s);
QCString substitute(const QCString &s,const QCString &src,const QCString &dst);
QCString substitute(const QCString &s,const QCString &src,const QCString &dst,int skip_seq);
+QCString substitute(const QCString &s,char srcChar,char dstChar);
QCString clearBlock(const char *s,const char *begin,const char *end);