Prefix command-line opened files with the current directory so relative paths will work better

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@547 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2006-07-11 13:48:24 +00:00
parent a1bca612ae
commit 1ae05d6a35
2 changed files with 35 additions and 4 deletions

View File

@ -1,3 +1,9 @@
2006-07-11 Nick Treleaven <nick.treleaven@btinternet.com>
* src/main.c: Prefix command-line opened files with the current
directory so relative paths will work better.
2006-07-10 Enrico Tröger <enrico.troeger@uvena.de>
* src/sci_cb.c: Autocompletion only works on blank lines.

View File

@ -316,6 +316,26 @@ static void main_init(void)
}
/* get the full file path of a command-line argument
* N.B. the result should be freed and may contain '/../' or '/./ ' */
gchar *get_argv_filename(const gchar *filename)
{
gchar *result;
if (g_path_is_absolute(filename))
result = g_strdup(filename);
else
{
//use current dir
gchar *cur_dir = g_get_current_dir();
result = g_strjoin(
G_DIR_SEPARATOR_S, cur_dir, filename, NULL);
g_free(cur_dir);
}
return result;
}
#ifdef HAVE_FIFO
static gboolean read_fifo(GIOChannel *source, GIOCondition condition, gpointer data)
{
@ -356,15 +376,18 @@ static void write_fifo(gint argc, gchar **argv)
gint i;
GIOChannel *ioc;
for(i = 1; i < argc; i++)
for(i = 1; i < argc && argv[i] != NULL; i++)
{
if (argv[i] && g_file_test(argv[i], G_FILE_TEST_IS_REGULAR || G_FILE_TEST_IS_SYMLINK))
gchar *filename = get_argv_filename(argv[i]);
if (filename && g_file_test(filename, G_FILE_TEST_IS_REGULAR || G_FILE_TEST_IS_SYMLINK))
{
ioc = g_io_channel_unix_new(open(fifo_name, O_WRONLY));
g_io_channel_write_chars(ioc, argv[i], -1, NULL, NULL);
g_io_channel_write_chars(ioc, filename, -1, NULL, NULL);
g_io_channel_flush(ioc, NULL);
g_io_channel_shutdown(ioc, TRUE, NULL);
}
g_free(filename);
}
}
@ -542,7 +565,9 @@ gint main(gint argc, gchar **argv)
{
if (opened < GEANY_MAX_OPEN_FILES)
{
document_open_file(-1, argv[i], 0, FALSE, NULL);
gchar *filename = get_argv_filename(argv[i]);
document_open_file(-1, filename, 0, FALSE, NULL);
g_free(filename);
opened++;
}
else