Use get_build_executable() in prepare_run_script().

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1568 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2007-05-24 16:12:12 +00:00
parent b7e499529d
commit 3af3268247
2 changed files with 54 additions and 35 deletions

View File

@ -2,6 +2,8 @@
* src/utils.h: * src/utils.h:
Add setptr() macro to free data and reassign to the same pointer. Add setptr() macro to free data and reassign to the same pointer.
* src/build.c:
Use get_build_executable() in prepare_run_script().
2007-05-24 Enrico Tröger <enrico.troeger@uvena.de> 2007-05-24 Enrico Tröger <enrico.troeger@uvena.de>

View File

@ -523,33 +523,24 @@ static GPid build_spawn_cmd(gint idx, const gchar *cmd, const gchar *dir)
} }
// Returns: NULL if there was an error, or the working directory the script was created in. /* Checks if the executable file corresponding to document idx exists.
static gchar *prepare_run_script(gint idx) * Returns the name part of the filename, without extension.
* Returns NULL if executable file doesn't exist. */
static gchar *get_build_executable(gint idx, const gchar *locale_filename)
{ {
gchar *long_executable = NULL; gchar *long_executable = NULL;
gchar *check_executable = NULL;
gchar *utf8_check_executable = NULL;
gchar *locale_filename = NULL;
gchar *cmd = NULL;
gchar *executable = NULL;
gchar *working_dir = NULL;
gboolean autoclose = FALSE;
struct stat st; struct stat st;
gboolean result = FALSE;
gchar *tmp;
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
long_executable = utils_remove_ext_from_filename(locale_filename); long_executable = utils_remove_ext_from_filename(locale_filename);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
tmp = long_executable; setptr(long_executable, g_strconcat(long_executable, ".exe", NULL));
long_executable = g_strconcat(long_executable, ".exe", NULL);
g_free(tmp);
#endif #endif
// only check for existing executable, if executable is required by %e // only check for existing executable, if executable is required by %e
if (strstr(doc_list[idx].file_type->programs->run_cmd, "%e") != NULL) if (strstr(doc_list[idx].file_type->programs->run_cmd, "%e") != NULL)
{ {
gchar *check_executable = NULL;
// add .class extension for JAVA source files (only for stat) // add .class extension for JAVA source files (only for stat)
if (doc_list[idx].file_type->id == GEANY_FILETYPES_JAVA) if (doc_list[idx].file_type->id == GEANY_FILETYPES_JAVA)
{ {
@ -571,30 +562,61 @@ static gchar *prepare_run_script(gint idx)
{ {
msgwin_status_add(_("Command stopped because the current file has no extension.")); msgwin_status_add(_("Command stopped because the current file has no extension."));
utils_beep(); utils_beep();
goto free_strings; g_free(check_executable);
return NULL;
} }
// check whether executable exists // check whether executable exists
if (g_stat(check_executable, &st) != 0) if (g_stat(check_executable, &st) != 0)
{ {
utf8_check_executable = utils_get_utf8_from_locale(check_executable); gchar *utf8_check_executable = utils_get_utf8_from_locale(check_executable);
msgwin_status_add(_("Failed to execute %s (make sure it is already built)"), msgwin_status_add(_("Failed to execute %s (make sure it is already built)"),
utf8_check_executable); utf8_check_executable);
goto free_strings; g_free(utf8_check_executable);
g_free(check_executable);
return NULL;
} }
} }
executable = g_path_get_basename(long_executable); // remove path
setptr(long_executable, g_path_get_basename(long_executable));
return long_executable;
}
// Returns: NULL if there was an error, or the working directory the script was created in.
static gchar *prepare_run_script(gint idx)
{
gchar *locale_filename = NULL;
gchar *cmd = NULL;
gchar *executable = NULL;
gchar *working_dir = NULL;
gboolean autoclose = FALSE;
gboolean result = FALSE;
gchar *tmp;
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
executable = get_build_executable(idx, locale_filename);
if (executable == NULL)
{
g_free(locale_filename);
return NULL;
}
working_dir = g_path_get_dirname(locale_filename); working_dir = g_path_get_dirname(locale_filename);
if (chdir(working_dir) != 0) if (chdir(working_dir) != 0)
{ {
gchar *utf8_working_dir = NULL; gchar *utf8_working_dir =
utf8_working_dir = utils_get_utf8_from_locale(working_dir); utils_get_utf8_from_locale(working_dir);
msgwin_status_add(_("Failed to change the working directory to %s"), utf8_working_dir); msgwin_status_add(_("Failed to change the working directory to %s"), utf8_working_dir);
g_free(utf8_working_dir); g_free(utf8_working_dir);
goto free_strings; g_free(working_dir);
g_free(executable);
g_free(locale_filename);
return NULL;
} }
// replace %f and %e in the run_cmd string // replace %f and %e in the run_cmd string
@ -610,24 +632,19 @@ static gchar *prepare_run_script(gint idx)
#endif #endif
// (RUN_SCRIPT_CMD should be ok in UTF8 without converting in locale because it contains no umlauts) // (RUN_SCRIPT_CMD should be ok in UTF8 without converting in locale because it contains no umlauts)
if (! build_create_shellscript(RUN_SCRIPT_CMD, cmd, autoclose)) result = build_create_shellscript(RUN_SCRIPT_CMD, cmd, autoclose);
if (! result)
{ {
utf8_check_executable = utils_get_utf8_from_locale(check_executable); gchar *utf8_cmd = utils_get_utf8_from_locale(cmd);
msgwin_status_add(_("Failed to execute \"%s\" (start-script could not be created)"), msgwin_status_add(_("Failed to execute \"%s\" (start-script could not be created)"),
utf8_check_executable); utf8_cmd);
} g_free(utf8_cmd);
else
{
result = TRUE;
} }
free_strings:
g_free(executable); g_free(executable);
g_free(cmd); g_free(cmd);
g_free(locale_filename); g_free(locale_filename);
g_free(utf8_check_executable);
g_free(check_executable);
g_free(long_executable);
if (result) if (result)
return working_dir; return working_dir;