added glob handling to qse_fs_cpfile()

This commit is contained in:
2016-12-12 16:19:59 +00:00
parent 78600e6edc
commit 7ca53162de
9 changed files with 317 additions and 433 deletions

View File

@ -12,7 +12,7 @@
# include <windows.h>
#endif
static int fs_del (qse_fs_t* fs, const qse_char_t* path)
static int fs_rm (qse_fs_t* fs, const qse_char_t* path)
{
qse_printf (QSE_T("Deleting [%s]\n"), path);
/*if (qse_strcmp(path, QSE_T("b/c")) == 0) return 0;*/
@ -40,12 +40,12 @@ static int fs_main (int argc, qse_char_t* argv[])
fs = qse_fs_open (QSE_MMGR_GETDFL(), 0);
qse_memset (&cbs, 0, QSE_SIZEOF(cbs));
cbs.del = fs_del;
cbs.rm = fs_rm;
qse_fs_setopt (fs, QSE_FS_CBS, &cbs);
if (qse_strcmp(argv[1], QSE_T("rmfile")) == 0)
{
if (qse_fs_delfile (fs, argv[2], QSE_FS_DELFILEMBS_GLOB) <= -1)
if (qse_fs_rmfile (fs, argv[2], QSE_FS_RMFILEMBS_GLOB) <= -1)
{
qse_fprintf (QSE_STDERR, QSE_T("cannot delete files - %d\n"), qse_fs_geterrnum(fs));
ret = -1;
@ -53,7 +53,7 @@ static int fs_main (int argc, qse_char_t* argv[])
}
else if (qse_strcmp(argv[1], QSE_T("rmfile-r")) == 0)
{
if (qse_fs_delfile (fs, argv[2], QSE_FS_DELFILE_GLOB | QSE_FS_DELFILE_RECURSIVE) <= -1)
if (qse_fs_rmfile (fs, argv[2], QSE_FS_RMFILE_GLOB | QSE_FS_RMFILE_RECURSIVE) <= -1)
{
qse_fprintf (QSE_STDERR, QSE_T("cannot delete files - %d\n"), qse_fs_geterrnum(fs));
ret = -1;
@ -61,7 +61,7 @@ static int fs_main (int argc, qse_char_t* argv[])
}
else if (qse_strcmp (argv[1], QSE_T("rmdir")) == 0)
{
if (qse_fs_deldir (fs, argv[2], QSE_FS_DELDIR_GLOB) <= -1)
if (qse_fs_rmdir (fs, argv[2], QSE_FS_RMDIR_GLOB) <= -1)
{
qse_fprintf (QSE_STDERR, QSE_T("cannot delete directories - %d\n"), qse_fs_geterrnum(fs));
ret = -1;
@ -69,7 +69,7 @@ static int fs_main (int argc, qse_char_t* argv[])
}
else if (qse_strcmp (argv[1], QSE_T("rmdir-r")) == 0)
{
if (qse_fs_deldir (fs, argv[2], QSE_FS_DELDIR_GLOB | QSE_FS_DELDIR_RECURSIVE) <= -1)
if (qse_fs_rmdir (fs, argv[2], QSE_FS_RMDIR_GLOB | QSE_FS_RMDIR_RECURSIVE) <= -1)
{
qse_fprintf (QSE_STDERR, QSE_T("cannot delete directories - %d\n"), qse_fs_geterrnum(fs));
ret = -1;

View File

@ -22,8 +22,17 @@ static void print_usage (const qse_char_t* argv0)
qse_fprintf (QSE_STDERR, QSE_T(" -p preserve\n"));
qse_fprintf (QSE_STDERR, QSE_T(" -r recursive\n"));
qse_fprintf (QSE_STDERR, QSE_T(" -s symlink\n"));
qse_fprintf (QSE_STDERR, QSE_T(" -g glob\n"));
}
static int fs_cp (qse_fs_t* fs, const qse_char_t* srcpath, const qse_char_t* dstpath, qse_uintmax_t total, qse_uintmax_t copied)
{
if (total == copied) qse_printf (QSE_T("Copied [%s] to [%s]\n"), srcpath, dstpath);
/*if (qse_strcmp(path, QSE_T("b/c")) == 0) return 0;*/
return 1;
}
static int fs_main (int argc, qse_char_t* argv[])
{
qse_fs_t* fs;
@ -34,7 +43,7 @@ static int fs_main (int argc, qse_char_t* argv[])
static qse_opt_t opt =
{
QSE_T("foprs"),
QSE_T("foprsg"),
QSE_NULL
};
@ -62,6 +71,10 @@ static int fs_main (int argc, qse_char_t* argv[])
cpfile_flags |= QSE_FS_CPFILE_SYMLINK;
break;
case QSE_T('g'):
cpfile_flags |= QSE_FS_CPFILE_GLOB;
break;
case QSE_T('?'):
qse_fprintf (QSE_STDERR, QSE_T("illegal option - '%c'\n"), opt.opt);
goto wrong_usage;
@ -79,11 +92,9 @@ static int fs_main (int argc, qse_char_t* argv[])
fs = qse_fs_open (QSE_MMGR_GETDFL(), 0);
/*
qse_memset (&cbs, 0, QSE_SIZEOF(cbs));
cbs.del = fs_del;
cbs.cp = fs_cp;
qse_fs_setopt (fs, QSE_FS_CBS, &cbs);
*/
if (qse_fs_cpfile (fs, argv[opt.ind], argv[opt.ind + 1], cpfile_flags) <= -1)
{