2005-02-20 04:17:07 -08:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
2007-06-02 09:33:43 -07:00
|
|
|
|
|
|
|
#ifndef _FILE_OFFSET_BITS
|
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
#endif
|
|
|
|
|
2005-09-29 17:46:15 -07:00
|
|
|
#include <ctype.h>
|
2006-01-06 10:46:30 -08:00
|
|
|
#include "ecore_file_private.h"
|
2007-02-04 05:14:16 -08:00
|
|
|
#include <errno.h>
|
2005-02-20 04:17:07 -08:00
|
|
|
|
2005-10-23 16:21:29 -07:00
|
|
|
|
2005-09-07 01:50:25 -07:00
|
|
|
static int init = 0;
|
|
|
|
|
2005-02-20 04:17:07 -08:00
|
|
|
/* externally accessible functions */
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-02-20 04:17:07 -08:00
|
|
|
ecore_file_init()
|
|
|
|
{
|
2005-09-07 01:57:08 -07:00
|
|
|
if (++init != 1) return init;
|
2005-09-07 01:50:25 -07:00
|
|
|
|
2005-02-20 04:17:07 -08:00
|
|
|
if (!ecore_file_monitor_init())
|
2005-09-07 01:50:25 -07:00
|
|
|
goto error;
|
2005-06-11 06:29:09 -07:00
|
|
|
if (!ecore_file_path_init())
|
2005-09-07 01:50:25 -07:00
|
|
|
goto error;
|
2005-06-17 16:52:32 -07:00
|
|
|
if (!ecore_file_download_init())
|
2005-09-07 01:50:25 -07:00
|
|
|
goto error;
|
|
|
|
return init;
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
ecore_file_monitor_shutdown();
|
|
|
|
ecore_file_path_shutdown();
|
|
|
|
ecore_file_download_shutdown();
|
|
|
|
|
|
|
|
return --init;
|
2005-02-20 04:17:07 -08:00
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-02-20 04:17:07 -08:00
|
|
|
ecore_file_shutdown()
|
|
|
|
{
|
2005-09-07 01:57:08 -07:00
|
|
|
if (--init != 0) return init;
|
2005-09-07 01:50:25 -07:00
|
|
|
|
|
|
|
ecore_file_monitor_shutdown();
|
|
|
|
ecore_file_path_shutdown();
|
|
|
|
ecore_file_download_shutdown();
|
|
|
|
|
|
|
|
return init;
|
2005-02-20 04:17:07 -08:00
|
|
|
}
|
|
|
|
|
2007-06-02 09:33:43 -07:00
|
|
|
EAPI long long
|
2005-02-21 08:03:08 -08:00
|
|
|
ecore_file_mod_time(const char *file)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat(file, &st) < 0) return 0;
|
|
|
|
return st.st_mtime;
|
|
|
|
}
|
|
|
|
|
2007-06-02 09:33:43 -07:00
|
|
|
EAPI long long
|
2005-12-08 16:02:21 -08:00
|
|
|
ecore_file_size(const char *file)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat(file, &st) < 0) return 0;
|
|
|
|
return st.st_size;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-02-21 08:03:08 -08:00
|
|
|
ecore_file_exists(const char *file)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2005-08-26 21:17:36 -07:00
|
|
|
/*Workaround so that "/" returns a true, otherwise we can't monitor "/" in ecore_file_monitor*/
|
|
|
|
if (stat(file, &st) < 0 && strcmp(file, "/")) return 0;
|
2005-02-20 04:17:07 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-02-21 08:03:08 -08:00
|
|
|
ecore_file_is_dir(const char *file)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat(file, &st) < 0) return 0;
|
|
|
|
if (S_ISDIR(st.st_mode)) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-02-21 08:03:08 -08:00
|
|
|
ecore_file_mkdir(const char *dir)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
if (mkdir(dir, default_mode) < 0) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-04-28 14:53:36 -07:00
|
|
|
ecore_file_rmdir(const char *dir)
|
|
|
|
{
|
|
|
|
if (rmdir(dir) < 0) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-04-28 14:53:36 -07:00
|
|
|
ecore_file_unlink(const char *file)
|
|
|
|
{
|
|
|
|
if (unlink(file) < 0) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-10-23 16:21:29 -07:00
|
|
|
ecore_file_recursive_rm(const char *dir)
|
2005-10-24 03:05:35 -07:00
|
|
|
{
|
2005-10-23 16:21:29 -07:00
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
2006-08-31 01:53:38 -07:00
|
|
|
char path[PATH_MAX], buf[PATH_MAX];;
|
|
|
|
struct stat st;
|
2006-10-15 02:32:25 -07:00
|
|
|
int ret;
|
2005-10-24 03:05:35 -07:00
|
|
|
|
2006-08-31 01:53:38 -07:00
|
|
|
if (readlink(dir, buf, sizeof(buf)) > 0)
|
2005-10-23 16:21:29 -07:00
|
|
|
{
|
2006-10-15 02:32:25 -07:00
|
|
|
return ecore_file_unlink(dir);
|
2006-08-31 01:53:38 -07:00
|
|
|
}
|
2006-10-15 02:32:25 -07:00
|
|
|
ret = stat(dir, &st);
|
|
|
|
if ((ret == 0) && (S_ISDIR(st.st_mode)))
|
2006-08-31 01:53:38 -07:00
|
|
|
{
|
2006-10-15 02:32:25 -07:00
|
|
|
ret = 1;
|
2006-10-15 02:18:26 -07:00
|
|
|
if (stat(dir, &st) == -1) return 0;
|
2006-08-31 01:53:38 -07:00
|
|
|
dirp = opendir(dir);
|
|
|
|
if (dirp)
|
|
|
|
{
|
|
|
|
while ((dp = readdir(dirp)))
|
2005-10-23 16:21:29 -07:00
|
|
|
{
|
2006-08-31 01:53:38 -07:00
|
|
|
if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, "..")))
|
|
|
|
{
|
|
|
|
snprintf(path, PATH_MAX, "%s/%s", dir, dp->d_name);
|
2006-10-15 02:32:25 -07:00
|
|
|
if (!ecore_file_recursive_rm(path))
|
|
|
|
ret = 0;
|
2006-08-31 01:53:38 -07:00
|
|
|
}
|
2005-10-23 16:21:29 -07:00
|
|
|
}
|
2006-08-31 01:53:38 -07:00
|
|
|
closedir(dirp);
|
2005-10-23 16:21:29 -07:00
|
|
|
}
|
2006-10-15 02:32:25 -07:00
|
|
|
if (!ecore_file_rmdir(dir)) ret = 0;
|
|
|
|
return ret;
|
2006-08-31 01:53:38 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-10-15 02:32:25 -07:00
|
|
|
if (ret == -1) return 0;
|
|
|
|
return ecore_file_unlink(dir);
|
2005-10-23 16:21:29 -07:00
|
|
|
}
|
2005-10-24 03:05:35 -07:00
|
|
|
|
2006-08-31 01:53:38 -07:00
|
|
|
return 1;
|
2005-10-23 16:21:29 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-02-21 08:03:08 -08:00
|
|
|
ecore_file_mkpath(const char *path)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
char ss[PATH_MAX];
|
2005-05-04 00:15:26 -07:00
|
|
|
int i;
|
2005-02-20 04:17:07 -08:00
|
|
|
|
|
|
|
ss[0] = 0;
|
|
|
|
i = 0;
|
|
|
|
while (path[i])
|
|
|
|
{
|
2005-05-04 00:15:26 -07:00
|
|
|
if (i == sizeof(ss) - 1) return 0;
|
|
|
|
ss[i] = path[i];
|
|
|
|
ss[i + 1] = 0;
|
2005-02-20 04:17:07 -08:00
|
|
|
if (path[i] == '/')
|
|
|
|
{
|
2005-05-04 00:15:26 -07:00
|
|
|
ss[i] = 0;
|
|
|
|
if ((ecore_file_exists(ss)) && (!ecore_file_is_dir(ss))) return 0;
|
|
|
|
else if (!ecore_file_exists(ss)) ecore_file_mkdir(ss);
|
|
|
|
ss[i] = '/';
|
2005-02-20 04:17:07 -08:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2005-05-04 00:15:26 -07:00
|
|
|
if ((ecore_file_exists(ss)) && (!ecore_file_is_dir(ss))) return 0;
|
|
|
|
else if (!ecore_file_exists(ss)) ecore_file_mkdir(ss);
|
2005-02-20 04:17:07 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-02-21 08:03:08 -08:00
|
|
|
ecore_file_cp(const char *src, const char *dst)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
FILE *f1, *f2;
|
|
|
|
char buf[16384];
|
2005-10-10 09:25:17 -07:00
|
|
|
char realpath1[PATH_MAX];
|
|
|
|
char realpath2[PATH_MAX];
|
2005-02-20 04:17:07 -08:00
|
|
|
size_t num;
|
2007-04-22 16:07:48 -07:00
|
|
|
int ret = 1;
|
2005-10-24 03:05:35 -07:00
|
|
|
|
2005-10-11 13:11:36 -07:00
|
|
|
if (!realpath(src, realpath1)) return 0;
|
|
|
|
if (realpath(dst, realpath2) && !strcmp(realpath1, realpath2)) return 0;
|
2005-10-10 14:10:04 -07:00
|
|
|
|
2005-02-20 04:17:07 -08:00
|
|
|
f1 = fopen(src, "rb");
|
|
|
|
if (!f1) return 0;
|
|
|
|
f2 = fopen(dst, "wb");
|
|
|
|
if (!f2)
|
|
|
|
{
|
|
|
|
fclose(f1);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-04-22 16:07:48 -07:00
|
|
|
while ((num = fread(buf, 1, sizeof(buf), f1)) > 0)
|
|
|
|
{
|
|
|
|
if (fwrite(buf, 1, num, f2) != num) ret = 0;
|
|
|
|
}
|
2005-02-20 04:17:07 -08:00
|
|
|
fclose(f1);
|
|
|
|
fclose(f2);
|
2007-04-22 16:07:48 -07:00
|
|
|
return ret;
|
2005-02-20 04:17:07 -08:00
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-05-11 01:52:27 -07:00
|
|
|
ecore_file_mv(const char *src, const char *dst)
|
|
|
|
{
|
|
|
|
if (ecore_file_exists(dst)) return 0;
|
2007-02-04 05:14:16 -08:00
|
|
|
if (rename(src, dst))
|
|
|
|
{
|
|
|
|
if (errno == EXDEV)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
stat(src, &st);
|
|
|
|
if (S_ISREG(st.st_mode))
|
|
|
|
{
|
|
|
|
ecore_file_cp(src, dst);
|
|
|
|
chmod(dst, st.st_mode);
|
|
|
|
ecore_file_unlink(src);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2005-05-11 01:52:27 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2006-01-02 16:18:42 -08:00
|
|
|
ecore_file_symlink(const char *src, const char *dest)
|
|
|
|
{
|
2007-02-04 05:14:16 -08:00
|
|
|
if (!symlink(src, dest)) return 1;
|
2006-01-02 16:18:42 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI char *
|
2005-02-21 08:03:08 -08:00
|
|
|
ecore_file_realpath(const char *file)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
|
2007-03-12 19:28:18 -07:00
|
|
|
if (!realpath(file, buf)) return strdup("");
|
2005-02-20 04:17:07 -08:00
|
|
|
return strdup(buf);
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI const char *
|
2005-10-31 01:14:41 -08:00
|
|
|
ecore_file_get_file(const char *path)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
char *result = NULL;
|
|
|
|
|
|
|
|
if (!path) return NULL;
|
|
|
|
if ((result = strrchr(path, '/'))) result++;
|
2006-01-06 10:46:30 -08:00
|
|
|
else result = (char *)path;
|
2005-02-20 04:17:07 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI char *
|
2006-01-20 01:13:19 -08:00
|
|
|
ecore_file_get_dir(const char *file)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
|
|
|
|
strncpy(buf, file, PATH_MAX);
|
|
|
|
p = strrchr(buf, '/');
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
return strdup(file);
|
|
|
|
}
|
2007-01-17 23:28:56 -08:00
|
|
|
|
|
|
|
if (p == buf) return strdup("/");
|
|
|
|
|
2005-02-20 04:17:07 -08:00
|
|
|
*p = 0;
|
|
|
|
return strdup(buf);
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-11-30 22:23:58 -08:00
|
|
|
ecore_file_can_read(const char *file)
|
|
|
|
{
|
|
|
|
if (!file) return 0;
|
|
|
|
if (!access(file, R_OK)) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-11-30 22:23:58 -08:00
|
|
|
ecore_file_can_write(const char *file)
|
|
|
|
{
|
|
|
|
if (!file) return 0;
|
|
|
|
if (!access(file, W_OK)) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI int
|
2005-02-21 08:03:08 -08:00
|
|
|
ecore_file_can_exec(const char *file)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
if (!file) return 0;
|
2005-10-02 08:44:24 -07:00
|
|
|
if (!access(file, X_OK)) return 1;
|
|
|
|
return 0;
|
2005-02-20 04:17:07 -08:00
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI char *
|
2005-02-21 08:03:08 -08:00
|
|
|
ecore_file_readlink(const char *link)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if ((count = readlink(link, buf, sizeof(buf))) < 0) return NULL;
|
|
|
|
buf[count] = 0;
|
|
|
|
return strdup(buf);
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI Ecore_List *
|
2005-02-21 08:03:08 -08:00
|
|
|
ecore_file_ls(const char *dir)
|
2005-02-20 04:17:07 -08:00
|
|
|
{
|
2005-11-09 21:44:41 -08:00
|
|
|
char *f;
|
2005-02-20 04:17:07 -08:00
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
2005-11-09 21:44:41 -08:00
|
|
|
Ecore_List *list;
|
2005-02-20 04:17:07 -08:00
|
|
|
|
|
|
|
dirp = opendir(dir);
|
|
|
|
if (!dirp) return NULL;
|
2005-10-06 11:48:03 -07:00
|
|
|
|
2005-04-14 06:35:50 -07:00
|
|
|
list = ecore_list_new();
|
2005-10-06 11:48:03 -07:00
|
|
|
ecore_list_set_free_cb(list, free);
|
|
|
|
|
2005-02-20 04:17:07 -08:00
|
|
|
while ((dp = readdir(dirp)))
|
|
|
|
{
|
|
|
|
if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, "..")))
|
|
|
|
{
|
2005-11-09 21:44:41 -08:00
|
|
|
f = strdup(dp->d_name);
|
|
|
|
ecore_list_append(list, f);
|
2005-02-20 04:17:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dirp);
|
2007-02-01 11:22:35 -08:00
|
|
|
|
2007-03-01 08:17:04 -08:00
|
|
|
ecore_list_sort(list, ECORE_COMPARE_CB(strcoll), ECORE_SORT_MIN);
|
2005-11-10 06:29:33 -08:00
|
|
|
|
2005-04-14 06:35:50 -07:00
|
|
|
ecore_list_goto_first(list);
|
|
|
|
return list;
|
2005-02-20 04:17:07 -08:00
|
|
|
}
|
2005-09-29 17:46:15 -07:00
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI char *
|
2005-09-29 17:46:15 -07:00
|
|
|
ecore_file_app_exe_get(const char *app)
|
|
|
|
{
|
|
|
|
char *p, *pp, *exe1 = NULL, *exe2 = NULL;
|
2005-10-07 10:48:09 -07:00
|
|
|
char *exe = NULL;
|
|
|
|
int in_quot_dbl = 0, in_quot_sing = 0, restart = 0;
|
2005-10-24 03:05:35 -07:00
|
|
|
|
2007-03-25 05:05:48 -07:00
|
|
|
if (!app) return NULL;
|
|
|
|
|
2005-09-29 17:46:15 -07:00
|
|
|
p = (char *)app;
|
2005-10-07 10:48:09 -07:00
|
|
|
restart:
|
2005-09-29 17:46:15 -07:00
|
|
|
while ((*p) && (isspace(*p))) p++;
|
|
|
|
exe1 = p;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if (in_quot_sing)
|
|
|
|
{
|
|
|
|
if (*p == '\'')
|
|
|
|
in_quot_sing = 0;
|
|
|
|
}
|
|
|
|
else if (in_quot_dbl)
|
|
|
|
{
|
|
|
|
if (*p == '\"')
|
|
|
|
in_quot_dbl = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*p == '\'')
|
|
|
|
in_quot_sing = 1;
|
|
|
|
else if (*p == '\"')
|
|
|
|
in_quot_dbl = 1;
|
|
|
|
if ((isspace(*p)) && (!((p > app) && (p[-1] != '\\'))))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
exe2 = p;
|
|
|
|
if (exe2 == exe1) return NULL;
|
2005-09-29 17:51:29 -07:00
|
|
|
if (*exe1 == '~')
|
|
|
|
{
|
|
|
|
char *homedir;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* Skip ~ */
|
|
|
|
exe1++;
|
|
|
|
|
|
|
|
homedir = getenv("HOME");
|
|
|
|
if (!homedir) return NULL;
|
|
|
|
len = strlen(homedir);
|
2005-10-07 10:48:09 -07:00
|
|
|
if (exe) free(exe);
|
2005-09-29 17:51:29 -07:00
|
|
|
exe = malloc(len + exe2 - exe1 + 2);
|
|
|
|
if (!exe) return NULL;
|
2005-09-29 17:55:27 -07:00
|
|
|
pp = exe;
|
2005-09-29 17:51:29 -07:00
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
strcpy(exe, homedir);
|
2005-09-29 17:55:27 -07:00
|
|
|
pp += len;
|
2005-09-29 17:51:29 -07:00
|
|
|
if (*(pp - 1) != '/')
|
|
|
|
{
|
|
|
|
*pp = '/';
|
|
|
|
pp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-07 10:48:09 -07:00
|
|
|
if (exe) free(exe);
|
2005-09-29 17:51:29 -07:00
|
|
|
exe = malloc(exe2 - exe1 + 1);
|
|
|
|
if (!exe) return NULL;
|
|
|
|
pp = exe;
|
|
|
|
}
|
2005-09-29 17:46:15 -07:00
|
|
|
p = exe1;
|
2005-10-07 10:48:09 -07:00
|
|
|
restart = 0;
|
2005-09-29 17:46:15 -07:00
|
|
|
in_quot_dbl = 0;
|
|
|
|
in_quot_sing = 0;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if (in_quot_sing)
|
|
|
|
{
|
|
|
|
if (*p == '\'')
|
|
|
|
in_quot_sing = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pp = *p;
|
|
|
|
pp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (in_quot_dbl)
|
|
|
|
{
|
|
|
|
if (*p == '\"')
|
|
|
|
in_quot_dbl = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* techcincally this is wrong. double quotes also accept
|
|
|
|
* special chars:
|
2005-10-24 03:05:35 -07:00
|
|
|
*
|
2005-09-29 17:46:15 -07:00
|
|
|
* $, `, \
|
|
|
|
*/
|
|
|
|
*pp = *p;
|
|
|
|
pp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* technically we should handle special chars:
|
2005-10-24 03:05:35 -07:00
|
|
|
*
|
2005-09-29 17:46:15 -07:00
|
|
|
* $, `, \, etc.
|
|
|
|
*/
|
2005-09-29 17:58:03 -07:00
|
|
|
if ((p > exe1) && (p[-1] == '\\'))
|
2005-09-29 17:46:15 -07:00
|
|
|
{
|
|
|
|
if (*p != '\n')
|
|
|
|
{
|
|
|
|
*pp = *p;
|
|
|
|
pp++;
|
|
|
|
}
|
|
|
|
}
|
2005-10-07 10:48:09 -07:00
|
|
|
else if ((p > exe1) && (*p == '='))
|
|
|
|
{
|
|
|
|
restart = 1;
|
|
|
|
*pp = *p;
|
|
|
|
pp++;
|
|
|
|
}
|
2005-09-29 17:46:15 -07:00
|
|
|
else if (*p == '\'')
|
|
|
|
in_quot_sing = 1;
|
|
|
|
else if (*p == '\"')
|
|
|
|
in_quot_dbl = 1;
|
|
|
|
else if (isspace(*p))
|
2005-10-07 10:48:09 -07:00
|
|
|
{
|
|
|
|
if (restart)
|
|
|
|
goto restart;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2005-09-29 17:46:15 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*pp = *p;
|
|
|
|
pp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
*pp = 0;
|
|
|
|
return exe;
|
|
|
|
}
|
2005-10-05 11:38:27 -07:00
|
|
|
|
2006-10-28 01:48:11 -07:00
|
|
|
EAPI char *
|
|
|
|
ecore_file_escape_name(const char *filename)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
char *q;
|
2006-10-28 18:08:28 -07:00
|
|
|
char buf[PATH_MAX];
|
2006-10-28 01:48:11 -07:00
|
|
|
|
|
|
|
p = filename;
|
|
|
|
q = buf;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if ((q - buf) > (PATH_MAX - 6)) return NULL;
|
|
|
|
if (
|
|
|
|
(*p == ' ') || (*p == '\t') || (*p == '\n') ||
|
|
|
|
(*p == '\\') || (*p == '\'') || (*p == '\"') ||
|
|
|
|
(*p == ';') || (*p == '!') || (*p == '#') ||
|
|
|
|
(*p == '$') || (*p == '%') || (*p == '&') ||
|
|
|
|
(*p == '*') || (*p == '(') || (*p == ')') ||
|
|
|
|
(*p == '[') || (*p == ']') || (*p == '{') ||
|
|
|
|
(*p == '}') || (*p == '|') || (*p == '<') ||
|
|
|
|
(*p == '>') || (*p == '?')
|
|
|
|
)
|
|
|
|
{
|
|
|
|
*q = '\\';
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
*q = *p;
|
|
|
|
q++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
*q = 0;
|
|
|
|
return strdup(buf);
|
|
|
|
}
|
|
|
|
|
2006-01-06 10:46:30 -08:00
|
|
|
EAPI char *
|
2005-10-05 11:38:27 -07:00
|
|
|
ecore_file_strip_ext(const char *path)
|
|
|
|
{
|
2005-10-07 10:32:31 -07:00
|
|
|
char *p, *file = NULL;
|
2005-10-05 11:38:27 -07:00
|
|
|
|
2005-10-07 10:32:31 -07:00
|
|
|
p = strrchr(path, '.');
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
file = strdup(path);
|
|
|
|
}
|
|
|
|
else if (p != path)
|
|
|
|
{
|
|
|
|
file = malloc(((p - path) + 1) * sizeof(char));
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
memcpy(file, path, (p - path));
|
|
|
|
file[p - path] = 0;
|
|
|
|
}
|
|
|
|
}
|
2005-10-05 11:38:27 -07:00
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|