diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/portable.cpp | 32 | ||||
-rw-r--r-- | src/util.cpp | 16 | ||||
-rw-r--r-- | src/util.h | 1 |
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, @@ -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); |