forked from enlightenment/efl
Expand the command line to handle multiple files, or multiple commands
with a single file each. Needs a serious pounding. The spec is incomplete on this stuff, no telling what strange ways apps will try to abuse it. SVN revision: 26850
This commit is contained in:
parent
abcd2dbe90
commit
a23d884945
|
@ -848,6 +848,7 @@ ecore_desktop_get_command(Ecore_Desktop * desktop, Ecore_List * files, int fill)
|
|||
if (desktop->exec_params)
|
||||
params = strdup(desktop->exec_params);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (files)
|
||||
{
|
||||
char *file;
|
||||
|
@ -856,21 +857,32 @@ if (files)
|
|||
while((file = ecore_list_next(files)) != NULL)
|
||||
printf("FILE FOR COMMAND IS - %s\n", file);
|
||||
}
|
||||
#endif
|
||||
|
||||
do
|
||||
{
|
||||
if (files)
|
||||
ecore_list_goto_first(files);
|
||||
|
||||
/* FIXME: The string handling could be better, but it's good enough for now. */
|
||||
do
|
||||
{
|
||||
if (fill)
|
||||
{
|
||||
Ecore_DList *command;
|
||||
char *p, *t, buf[PATH_MAX + 10];
|
||||
char *p, *t, buf[PATH_MAX + 10], *big_buf = NULL;
|
||||
int len = 0;
|
||||
|
||||
if (!params) params = strdup("%F");
|
||||
if (!params) goto error;
|
||||
command = ecore_dlist_new();
|
||||
if (!command) goto error;
|
||||
|
||||
ecore_dlist_set_free_cb(command, free);
|
||||
/* Grab a fresh copy of the params. The default is %F as per rasters request. */
|
||||
if (params) free(params);
|
||||
if (desktop->exec_params)
|
||||
params = strdup(desktop->exec_params);
|
||||
else
|
||||
params = strdup("%F");
|
||||
if (!params) goto error;
|
||||
/* Split it up. */
|
||||
t = params;
|
||||
for (p = params; *p; p++)
|
||||
{
|
||||
|
@ -878,6 +890,7 @@ do
|
|||
{
|
||||
*p = '\0';
|
||||
ecore_dlist_append(command, strdup(t));
|
||||
len += strlen(t);
|
||||
*p = '%';
|
||||
t = p;
|
||||
}
|
||||
|
@ -886,10 +899,13 @@ do
|
|||
{
|
||||
ecore_dlist_append(command, strdup(t));
|
||||
}
|
||||
free(params);
|
||||
params = NULL;
|
||||
t = NULL;
|
||||
p = NULL;
|
||||
/* Check the bits for replacables. */
|
||||
if (!ecore_dlist_is_empty(command))
|
||||
{
|
||||
if (files)
|
||||
ecore_list_goto_first(files);
|
||||
ecore_dlist_goto_first(command);
|
||||
while ((p = ecore_dlist_next(command)) != NULL)
|
||||
{
|
||||
|
@ -970,10 +986,16 @@ do
|
|||
default:
|
||||
break;
|
||||
}
|
||||
/* TAke care of any file expansions. */
|
||||
if (do_file && (files))
|
||||
{
|
||||
char *file;
|
||||
size_t big_len;
|
||||
|
||||
/* Pre load the big_buf so that the reallocs are quick. WEemight eventually need more than PATH_MAX. */
|
||||
big_buf = malloc(PATH_MAX);
|
||||
big_buf[0] = '\0';
|
||||
big_len = 0;
|
||||
while((file = ecore_list_next(files)) != NULL)
|
||||
{
|
||||
char *text = NULL, *escaped = NULL;
|
||||
|
@ -982,11 +1004,9 @@ do
|
|||
{
|
||||
/* FIXME: The spec is unclear about what they mean by URL,
|
||||
* GIMP uses %U, but doesn't understand file://foo
|
||||
* GIMP is also happy if you pass it a raw file name.
|
||||
* For now, just make this the same as is_file.
|
||||
*/
|
||||
// text = malloc(strlen(file) + 10);
|
||||
// if (text)
|
||||
// sprintf(text, "file://%s", file);
|
||||
text = strdup(file);
|
||||
}
|
||||
else if (is_directory)
|
||||
|
@ -1003,25 +1023,44 @@ do
|
|||
text = strdup(ecore_file_get_file(file));
|
||||
else
|
||||
{
|
||||
/* FIXME: If the file is on the net, download first and point to temp file. */
|
||||
/* FIXME: If the file is on the net, download
|
||||
* first and point to temp file.
|
||||
*
|
||||
* This I think is the clue to how the whole
|
||||
* file/url thing is supposed to work. This is
|
||||
* purely speculation though, and you can get
|
||||
* into lots of trouble with specs that require
|
||||
* geussing like this.
|
||||
*
|
||||
* %u%U - pass filenames or URLS.
|
||||
* %f%F - pass filenames, download URLS and pass path to temp file.
|
||||
*
|
||||
* WE are not currently getting URLs passed to us anyway.
|
||||
*/
|
||||
text = strdup(file);
|
||||
}
|
||||
if (text)
|
||||
{
|
||||
escaped = ecore_file_escape_name(text);
|
||||
free(text);
|
||||
text = NULL;
|
||||
}
|
||||
/* Add it to the big buf. */
|
||||
if (escaped)
|
||||
{
|
||||
/* FIXME: Need to append these if we are looping. */
|
||||
snprintf(buf, sizeof(buf), "%s", escaped);
|
||||
t = buf;
|
||||
big_len += strlen(escaped) + 1;
|
||||
big_buf = realloc(big_buf, big_len);
|
||||
strcat(big_buf, " ");
|
||||
strcat(big_buf, escaped);
|
||||
t = big_buf;
|
||||
free(escaped);
|
||||
escaped = NULL;
|
||||
}
|
||||
if (is_single)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Insert this bit into the command. */
|
||||
if (t)
|
||||
{
|
||||
len += strlen(t);
|
||||
|
@ -1030,9 +1069,14 @@ do
|
|||
ecore_dlist_next(command);
|
||||
ecore_dlist_next(command);
|
||||
}
|
||||
len += strlen(p);
|
||||
if (big_buf)
|
||||
{
|
||||
free(big_buf);
|
||||
big_buf = NULL;
|
||||
}
|
||||
free(params);
|
||||
}
|
||||
|
||||
/* Put it all together. */
|
||||
params = malloc(len + 1);
|
||||
if (params)
|
||||
{
|
||||
|
@ -1050,15 +1094,21 @@ do
|
|||
ecore_list_destroy(command);
|
||||
}
|
||||
|
||||
/* FIXME: still need to loop if there are files left. */
|
||||
/* Add the command to the list of commands. */
|
||||
/* NOTE: params might be just desktop->exec_params, or it might have been built from bits. */
|
||||
sub_result = ecore_desktop_merge_command(desktop->exec, params);
|
||||
if (sub_result)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("FULL COMMAND IS - %s\n", sub_result);
|
||||
#endif
|
||||
ecore_list_append(result, sub_result);
|
||||
}
|
||||
}
|
||||
while((files) && (ecore_list_current(files)));
|
||||
/* If there is any "single file" things to fill in, and we have more files,
|
||||
* go back and do it all again for the next file.
|
||||
*/
|
||||
}
|
||||
while((fill) && (files) && (ecore_list_current(files)));
|
||||
|
||||
error:
|
||||
if (params) free(params);
|
||||
|
|
Loading…
Reference in New Issue