Revision: 4050 http://geany.svn.sourceforge.net/geany/?rev=4050&view=rev Author: eht16 Date: 2009-08-02 13:33:39 +0000 (Sun, 02 Aug 2009)
Log Message: ----------- Expand system environment variables (%variableName%) on Windows when running Build commands.
Modified Paths: -------------- trunk/ChangeLog trunk/src/build.c trunk/src/win32.c trunk/src/win32.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-08-01 10:26:58 UTC (rev 4049) +++ trunk/ChangeLog 2009-08-02 13:33:39 UTC (rev 4050) @@ -1,3 +1,10 @@ +2009-08-02 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * src/build.c, src/win32.h, src/win32.c: + Expand system environment variables (%variableName%) on Windows when + running Build commands. + + 2009-07-30 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/keybindings.c:
Modified: trunk/src/build.c =================================================================== --- trunk/src/build.c 2009-08-01 10:26:58 UTC (rev 4049) +++ trunk/src/build.c 2009-08-02 13:33:39 UTC (rev 4050) @@ -982,12 +982,18 @@ { FILE *fp; gchar *str; +#ifdef G_OS_WIN32 + gchar *expanded_cmd; +#endif
fp = g_fopen(fname, "w"); if (! fp) return FALSE; #ifdef G_OS_WIN32 - str = g_strdup_printf("%s\n\n%s\ndel "%%0"\n\npause\n", cmd, (autoclose) ? "" : "pause"); + /* Expand environment variables like %blah%. */ + expanded_cmd = win32_expand_environment_variables(cmd); + str = g_strdup_printf("%s\n\n%s\ndel "%%0"\n\npause\n", expanded_cmd, (autoclose) ? "" : "pause"); + g_free(expanded_cmd); #else str = g_strdup_printf( "#!/bin/sh\n\nrm $0\n\n%s\n\necho "\n\n------------------\n(program exited with code: $?)" \
Modified: trunk/src/win32.c =================================================================== --- trunk/src/win32.c 2009-08-01 10:26:58 UTC (rev 4049) +++ trunk/src/win32.c 2009-08-02 13:33:39 UTC (rev 4050) @@ -937,11 +937,23 @@ }
+gchar *win32_expand_environment_variables(const gchar *str) +{ + gchar expCmdline[32768]; /* 32768 is the limit for ExpandEnvironmentStrings() */ + + if (ExpandEnvironmentStrings((LPCTSTR) str, (LPTSTR) expCmdline, sizeof(expCmdline)) != 0) + return g_strdup(expCmdline); + else + return g_strdup(str); +} + + static gboolean CreateChildProcess(geany_win32_spawn *gw_spawn, TCHAR *szCmdline, const TCHAR *dir, GError **error) { PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; BOOL bFuncRetn = FALSE; + gchar *expandedCmdline;
/* Set up members of the PROCESS_INFORMATION structure. */ ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION) ); @@ -955,9 +967,12 @@ siStartInfo.hStdInput = gw_spawn->hChildStdinRd; siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
+ /* Expand environment variables like %blah%. */ + expandedCmdline = win32_expand_environment_variables(szCmdline); + /* Create the child process. */ bFuncRetn = CreateProcess(NULL, - szCmdline, /* command line */ + expandedCmdline, /* command line */ NULL, /* process security attributes */ NULL, /* primary thread security attributes */ TRUE, /* handles are inherited */ @@ -967,6 +982,8 @@ &siStartInfo, /* STARTUPINFO pointer */ &piProcInfo); /* receives PROCESS_INFORMATION */
+ g_free(expandedCmdline); + if (bFuncRetn == 0) { gchar *msg = g_win32_error_message(GetLastError());
Modified: trunk/src/win32.h =================================================================== --- trunk/src/win32.h 2009-08-01 10:26:58 UTC (rev 4049) +++ trunk/src/win32.h 2009-08-02 13:33:39 UTC (rev 4050) @@ -63,4 +63,6 @@
gchar *win32_get_installation_dir(void);
+gchar *win32_expand_environment_variables(const gchar *str); + #endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.