added an experimental and incomplenet glob function

This commit is contained in:
2012-08-30 16:36:37 +00:00
parent 8367a4cd12
commit fde4ee404b
43 changed files with 1118 additions and 413 deletions

View File

@ -1,9 +1,9 @@
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# Makefile.in generated by automake 1.11.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
# Inc.
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@ -491,10 +491,15 @@ install-am: all-am
installcheck: installcheck-recursive
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:

View File

@ -1,9 +1,9 @@
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# Makefile.in generated by automake 1.11.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
# Inc.
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@ -71,6 +71,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__uninstall_files_from_dir = { \
test -z "$$files" \
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
@ -361,11 +367,11 @@ clean-libLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libqseawk.la: $(libqseawk_la_OBJECTS) $(libqseawk_la_DEPENDENCIES)
libqseawk.la: $(libqseawk_la_OBJECTS) $(libqseawk_la_DEPENDENCIES) $(EXTRA_libqseawk_la_DEPENDENCIES)
$(libqseawk_la_LINK) -rpath $(libdir) $(libqseawk_la_OBJECTS) $(libqseawk_la_LIBADD) $(LIBS)
libqseawkmp.la: $(libqseawkmp_la_OBJECTS) $(libqseawkmp_la_DEPENDENCIES)
libqseawkmp.la: $(libqseawkmp_la_OBJECTS) $(libqseawkmp_la_DEPENDENCIES) $(EXTRA_libqseawkmp_la_DEPENDENCIES)
$(libqseawkmp_la_LINK) $(am_libqseawkmp_la_rpath) $(libqseawkmp_la_OBJECTS) $(libqseawkmp_la_LIBADD) $(LIBS)
libqseawkxx.la: $(libqseawkxx_la_OBJECTS) $(libqseawkxx_la_DEPENDENCIES)
libqseawkxx.la: $(libqseawkxx_la_OBJECTS) $(libqseawkxx_la_DEPENDENCIES) $(EXTRA_libqseawkxx_la_DEPENDENCIES)
$(libqseawkxx_la_LINK) $(am_libqseawkxx_la_rpath) $(libqseawkxx_la_OBJECTS) $(libqseawkxx_la_LIBADD) $(LIBS)
mostlyclean-compile:
@ -543,10 +549,15 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:

View File

@ -39,6 +39,7 @@ libqsecmn_la_SOURCES = \
fs.c \
fs-err.c \
fs-move.c \
glob.c \
hton.c \
ipad.c \
lda.c \

View File

@ -1,9 +1,9 @@
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# Makefile.in generated by automake 1.11.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
# Inc.
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@ -72,23 +72,29 @@ am__nobase_list = $(am__nobase_strip_setup); \
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__uninstall_files_from_dir = { \
test -z "$$files" \
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
libqsecmn_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am_libqsecmn_la_OBJECTS = alg-rand.lo alg-search.lo alg-sort.lo \
assert.lo chr.lo cp949.lo cp950.lo dll.lo env.lo gdl.lo htb.lo \
fio.lo fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo hton.lo \
ipad.lo lda.lo main.lo mbwc.lo mbwc-str.lo mem.lo nwad.lo \
nwio.lo oht.lo opt.lo path-basename.lo path-canon.lo pio.lo \
pma.lo rbt.lo rex.lo sio.lo sll.lo slmb.lo stdio.lo str-beg.lo \
str-cat.lo str-chr.lo str-cnv.lo str-cmp.lo str-cpy.lo \
str-del.lo str-dup.lo str-dynm.lo str-dynw.lo str-end.lo \
str-excl.lo str-fcpy.lo str-fnmat.lo str-incl.lo str-len.lo \
str-pac.lo str-pbrk.lo str-put.lo str-rev.lo str-rot.lo \
str-set.lo str-spl.lo str-spn.lo str-str.lo str-subst.lo \
str-tok.lo str-trm.lo str-word.lo time.lo tio.lo tre.lo \
tre-ast.lo tre-compile.lo tre-match-backtrack.lo \
fio.lo fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo glob.lo \
hton.lo ipad.lo lda.lo main.lo mbwc.lo mbwc-str.lo mem.lo \
nwad.lo nwio.lo oht.lo opt.lo path-basename.lo path-canon.lo \
pio.lo pma.lo rbt.lo rex.lo sio.lo sll.lo slmb.lo stdio.lo \
str-beg.lo str-cat.lo str-chr.lo str-cnv.lo str-cmp.lo \
str-cpy.lo str-del.lo str-dup.lo str-dynm.lo str-dynw.lo \
str-end.lo str-excl.lo str-fcpy.lo str-fnmat.lo str-incl.lo \
str-len.lo str-pac.lo str-pbrk.lo str-put.lo str-rev.lo \
str-rot.lo str-set.lo str-spl.lo str-spn.lo str-str.lo \
str-subst.lo str-tok.lo str-trm.lo str-word.lo time.lo tio.lo \
tre.lo tre-ast.lo tre-compile.lo tre-match-backtrack.lo \
tre-match-parallel.lo tre-parse.lo tre-stack.lo utf8.lo xma.lo
libqsecmn_la_OBJECTS = $(am_libqsecmn_la_OBJECTS)
libqsecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
@ -321,6 +327,7 @@ libqsecmn_la_SOURCES = \
fs.c \
fs-err.c \
fs-move.c \
glob.c \
hton.c \
ipad.c \
lda.c \
@ -455,9 +462,9 @@ clean-libLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libqsecmn.la: $(libqsecmn_la_OBJECTS) $(libqsecmn_la_DEPENDENCIES)
libqsecmn.la: $(libqsecmn_la_OBJECTS) $(libqsecmn_la_DEPENDENCIES) $(EXTRA_libqsecmn_la_DEPENDENCIES)
$(libqsecmn_la_LINK) -rpath $(libdir) $(libqsecmn_la_OBJECTS) $(libqsecmn_la_LIBADD) $(LIBS)
libqsecmnxx.la: $(libqsecmnxx_la_OBJECTS) $(libqsecmnxx_la_DEPENDENCIES)
libqsecmnxx.la: $(libqsecmnxx_la_OBJECTS) $(libqsecmnxx_la_DEPENDENCIES) $(EXTRA_libqsecmnxx_la_DEPENDENCIES)
$(libqsecmnxx_la_LINK) $(am_libqsecmnxx_la_rpath) $(libqsecmnxx_la_OBJECTS) $(libqsecmnxx_la_LIBADD) $(LIBS)
mostlyclean-compile:
@ -484,6 +491,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs-move.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glob.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/htb.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hton.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipad.Plo@am__quote@
@ -694,10 +702,15 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:

354
qse/lib/cmn/glob.c Normal file
View File

@ -0,0 +1,354 @@
/*
* $Id$
*
Copyright 2006-2012 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qse/cmn/glob.h>
#include <qse/cmn/str.h>
#include <qse/cmn/mbwc.h>
#include "mem.h"
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# define SEPC QSE_T('\\')
#else
# define SEPC QSE_T('/')
#endif
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# define IS_SEP(c) ((c) == QSE_T('/') || (c) == QSE_T('\\'))
#else
# define IS_SEP(c) ((c) == QSE_T('/'))
#endif
#define IS_NIL(c) ((c) == QSE_T('\0'))
#define IS_SEP_OR_NIL(c) (IS_SEP(c) || IS_NIL(c))
#define IS_WILD(c) ((c) == QSE_T('*') || (c) == QSE_T('?') || (c) == QSE_T('['))
#define GLOB_MULTI QSE_T('*')
#define GLOB_SINGLE QSE_T('?')
#define GLOB_RANGE QSE_T("[]")
#define GLOB_NEGATE QSE_T("^!")
#define string_has_globs(ptr) \
(qse_strpbrk (ptr, QSE_T("*?[")) != QSE_NULL)
#define string_has_globs2(ptr,len) \
(qse_strxpbrk (ptr, len, QSE_T("*?[")) != QSE_NULL)
struct glob_t
{
qse_mmgr_t* mmgr;
qse_cmgr_t* cmgr;
qse_str_t path;
int depth;
};
typedef struct glob_t glob_t;
static int record_a_match (const qse_char_t* x)
{
wprintf (L"MATCH => [%.*S]\n", (int)qse_strlen(x), x);
return 0;
}
static int path_exists (glob_t* g, const qse_char_t* name)
{
struct stat st;
int x;
#if defined(QSE_CHAR_IS_MCHAR)
x = lstat (name, &st);
#else
qse_mchar_t* ptr;
ptr = qse_wcstombsdup (name, g->mmgr);
if (ptr == QSE_NULL) return -1;
x = lstat (ptr, &st);
QSE_MMGR_FREE (g->mmgr, ptr);
#endif
return (x == 0)? 1: 0;
}
static int path_is_directory (glob_t* g, const qse_char_t* name)
{
struct stat st;
int x;
#if defined(QSE_CHAR_IS_MCHAR)
x = lstat (name, &st);
#else
qse_mchar_t* ptr;
ptr = qse_wcstombsdup (name, g->mmgr);
if (ptr == QSE_NULL) return -1;
x = lstat (ptr, &st);
QSE_MMGR_FREE (g->mmgr, ptr);
#endif
return (x == 0 && S_ISDIR(st.st_mode))? 1: 0;
}
struct segment_t
{
enum
{
NONE,
ROOT,
NORMAL
} type;
const qse_char_t* ptr;
qse_size_t len;
qse_char_t sep; /* preceeding separator */
unsigned int wild: 1;
unsigned int next: 1;
};
typedef struct segment_t segment_t;
static int get_next_segment (segment_t* seg)
{
if (seg->type == NONE)
{
/* seg->ptr must point to the beginning of the pattern
* and seg->len must be zero when seg->type is NONE. */
if (IS_NIL(seg->ptr[0]))
{
/* nothing to do */
}
else if (IS_SEP(seg->ptr[0]))
{
seg->type = ROOT;
seg->len = 1;
seg->next = IS_NIL(seg->ptr[1])? 0: 1;
}
else
{
seg->type = NORMAL;
seg->sep = QSE_T('\0');
seg->wild = 0;
do
{
if (IS_WILD(seg->ptr[seg->len])) seg->wild = 1;
seg->len++;
}
while (!IS_SEP_OR_NIL(seg->ptr[seg->len]));
seg->next = IS_NIL(seg->ptr[seg->len])? 0: 1;
}
}
else if (seg->type == ROOT)
{
seg->type = NORMAL;
seg->ptr = &seg->ptr[seg->len];
seg->len = 0;
seg->sep = QSE_T('\0');
seg->wild = 0;
while (!IS_SEP_OR_NIL(seg->ptr[seg->len]))
{
if (IS_WILD(seg->ptr[seg->len])) seg->wild = 1;
seg->len++;
}
seg->next = IS_NIL(seg->ptr[seg->len])? 0: 1;
}
else
{
QSE_ASSERT (seg->type == NORMAL);
seg->ptr = &seg->ptr[seg->len + 1];
seg->len = 0;
seg->wild = 0;
if (IS_NIL(seg->ptr[-1]))
{
seg->type = NONE;
seg->next = 0;
}
else
{
seg->sep = seg->ptr[-1];
while (!IS_SEP_OR_NIL(seg->ptr[seg->len]))
{
if (IS_WILD(seg->ptr[seg->len])) seg->wild = 1;
seg->len++;
}
seg->next = IS_NIL(seg->ptr[seg->len])? 0: 1;
}
}
return seg->type;
}
DIR* xopendir (glob_t* g, const qse_char_t* path)
{
if (path[0] == QSE_T('\0')) path = QSE_T(".");
#if defined(QSE_CHAR_IS_MCHAR)
return opendir (path)
#else
DIR* dp;
qse_mchar_t* mptr;
mptr = qse_wcstombsdup (path, g->mmgr);
if (mptr == QSE_NULL) return QSE_NULL;
dp = opendir (mptr);
QSE_MMGR_FREE (g->mmgr, mptr);
return dp;
#endif
}
int xreaddir (glob_t* g, DIR* dp, qse_str_t* path)
{
struct dirent* de;
#if defined(QSE_CHAR_IS_MCHAR)
/* nothing */
#else
qse_size_t ml, wl, tmp;
#endif
read_more:
de = readdir (dp);
if (de == NULL) return 0;
if (qse_mbscmp (de->d_name, QSE_MT(".")) == 0 ||
qse_mbscmp (de->d_name, QSE_MT("..")) == 0) goto read_more;
#if defined(QSE_CHAR_IS_MCHAR)
if (qse_str_cat (path, de->d_name) == (qse_size_t)-1) return -1;
#else
tmp = QSE_STR_LEN(path);
if (qse_mbstowcswithcmgr (de->d_name, &ml, QSE_NULL, &wl, g->cmgr) <= -1 ||
qse_str_setlen (path, tmp + wl) == (qse_size_t)-1) return -1;
qse_mbstowcswithcmgr (de->d_name, &ml, QSE_STR_CPTR(&g->path,tmp), &wl, g->cmgr);
#endif
return 1;
}
static int search (glob_t* g, segment_t* seg)
{
segment_t save = *seg;
g->depth++;
//wprintf (L"CALL DEPTH = %d\n", (int)g->depth);
while (get_next_segment(seg) != NONE)
{
QSE_ASSERT (seg->type != NONE);
if (seg->wild)
{
DIR* dp;
//wprintf (L"OPENDING %.*S\n", (int)QSE_STR_LEN(&g->path), QSE_STR_PTR(&g->path));
dp = xopendir (g, QSE_STR_PTR(&g->path));
if (dp)
{
qse_size_t tmp, tmp2;
tmp = QSE_STR_LEN(&g->path);
if (seg->sep && qse_str_ccat (&g->path, seg->sep) == (qse_size_t)-1) return -1;
tmp2 = QSE_STR_LEN(&g->path);
while (1)
{
qse_str_setlen (&g->path, tmp2);
if (xreaddir (g, dp, &g->path) <= 0) break;
if (seg->next)
{
if (qse_strnfnmat (QSE_STR_CPTR(&g->path,tmp2), seg->ptr, seg->len, 0) > 0 &&
search (g, seg) <= -1) return -1;
}
else
{
//wprintf (L"CHECKING %S [%.*S]\n", QSE_STR_CPTR(&g->path,tmp2), (int)seg->len, seg->ptr);
if (qse_strnfnmat (QSE_STR_CPTR(&g->path,tmp2), seg->ptr, seg->len, 0) > 0)
{
record_a_match (QSE_STR_PTR(&g->path));
}
}
}
qse_str_setlen (&g->path, tmp); /* TODO: error check */
closedir (dp);
//wprintf (L"CLOSED %S\n", QSE_STR_PTR(&g->path));
}
break;
}
else
{
if ((seg->sep && qse_str_ccat (&g->path, seg->sep) == (qse_size_t)-1) ||
qse_str_ncat (&g->path, seg->ptr, seg->len) == (qse_size_t)-1) return -1;
//wprintf (L">> [%.*S]\n", (int)QSE_STR_LEN(&g->path), QSE_STR_PTR(&g->path));
if (!seg->next && path_exists(g, QSE_STR_PTR(&g->path)))
{
record_a_match (QSE_STR_PTR(&g->path));
}
}
}
*seg = save;
g->depth--;
return 0;
}
int qse_globwithcmgr (const qse_char_t* pattern, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
{
segment_t seg;
glob_t g;
int x;
QSE_MEMSET (&g, 0, QSE_SIZEOF(g));
g.mmgr = mmgr;
g.cmgr = cmgr;
if (qse_str_init (&g.path, mmgr, 512) <= -1) return -1;
QSE_MEMSET (&seg, 0, QSE_SIZEOF(seg));
seg.type = NONE;
seg.ptr = pattern;
seg.len = 0;
x = search (&g, &seg);
qse_str_fini (&g.path);
return x;
}
int qse_glob (const qse_char_t* pattern, qse_mmgr_t* mmgr)
{
return qse_globwithcmgr (pattern, mmgr, qse_getdflcmgr());
}

View File

@ -20,13 +20,12 @@
#include <qse/cmn/path.h>
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# define ISMSEP(c) ((c) == QSE_MT('/') || (c) == QSE_MT('\\'))
# define ISWSEP(c) ((c) == QSE_WT('/') || (c) == QSE_WT('\\'))
# define IS_MSEP(c) ((c) == QSE_MT('/') || (c) == QSE_MT('\\'))
# define IS_WSEP(c) ((c) == QSE_WT('/') || (c) == QSE_WT('\\'))
#else
# define ISMSEP(c) ((c) == QSE_MT('/'))
# define ISWSEP(c) ((c) == QSE_WT('/'))
# define IS_MSEP(c) ((c) == QSE_MT('/'))
# define IS_WSEP(c) ((c) == QSE_WT('/'))
#endif
const qse_mchar_t* qse_mbsbasename (const qse_mchar_t* path)
@ -35,7 +34,7 @@ const qse_mchar_t* qse_mbsbasename (const qse_mchar_t* path)
for (p = path; *p != QSE_MT('\0'); p++)
{
if (ISMSEP(*p)) last = p;
if (IS_MSEP(*p)) last = p;
}
return (last == QSE_NULL)? path: (last + 1);
@ -47,7 +46,7 @@ const qse_wchar_t* qse_wcsbasename (const qse_wchar_t* path)
for (p = path; *p != QSE_WT('\0'); p++)
{
if (ISWSEP(*p)) last = p;
if (IS_WSEP(*p)) last = p;
}
return (last == QSE_NULL)? path: (last + 1);

View File

@ -21,12 +21,13 @@
#include <qse/cmn/path.h>
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# define ISSEP(c) ((c) == QSE_T('/') || (c) == QSE_T('\\'))
# define IS_SEP(c) ((c) == QSE_T('/') || (c) == QSE_T('\\'))
#else
# define ISSEP(c) ((c) == QSE_T('/'))
# define IS_SEP(c) ((c) == QSE_T('/'))
#endif
#define ISSEPNIL(c) (ISSEP(c) || ((c) == QSE_T('\0')))
#define IS_NIL(c) ((c) == QSE_T('\0'))
#define IS_SEP_OR_NIL(c) (IS_SEP(c) || IS_NIL(c))
#define ISDRIVE(s) \
(((s[0] >= QSE_T('A') && s[0] <= QSE_T('Z')) || \
@ -35,7 +36,7 @@
int qse_isabspath (const qse_char_t* path)
{
if (ISSEP(path[0])) return 1;
if (IS_SEP(path[0])) return 1;
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
/* a drive like c:tmp is absolute in positioning the drive.
* but the path within the drive is kind of relative */
@ -90,24 +91,24 @@ qse_size_t qse_canonpath (const qse_char_t* path, qse_char_t* canon, int flags)
*dst++ = *ptr++; /* colon */
is_drive = 1;
if (ISSEP(*ptr))
if (IS_SEP(*ptr))
{
*dst++ = *ptr++; /* root directory */
has_root = 1;
}
}
else if (ISSEP(*ptr))
else if (IS_SEP(*ptr))
{
*dst++ = *ptr++; /* root directory */
has_root = 1;
#if defined(_WIN32)
/* handle UNC path for Windows */
if (ISSEP(*ptr))
if (IS_SEP(*ptr))
{
*dst++ = *ptr++;
if (ISSEPNIL(*ptr))
if (IS_SEP_OR_NIL(*ptr))
{
/* if there is another separator after \\,
* it's not an UNC path. */
@ -116,14 +117,14 @@ qse_size_t qse_canonpath (const qse_char_t* path, qse_char_t* canon, int flags)
else
{
/* if it starts with \\, process host name */
do { *dst++ = *ptr++; } while (!ISSEPNIL(*ptr));
if (ISSEP(*ptr)) *dst++ = *ptr++;
do { *dst++ = *ptr++; } while (!IS_SEP_OR_NIL(*ptr));
if (IS_SEP(*ptr)) *dst++ = *ptr++;
}
}
#endif
}
#else
if (ISSEP(*ptr))
if (IS_SEP(*ptr))
{
*dst++ = *ptr++; /* root directory */
has_root = 1;
@ -140,14 +141,14 @@ qse_size_t qse_canonpath (const qse_char_t* path, qse_char_t* canon, int flags)
qse_size_t seglen;
/* skip duplicate separators */
while (ISSEP(*ptr)) ptr++;
while (IS_SEP(*ptr)) ptr++;
/* end of path reached */
if (*ptr == QSE_T('\0')) break;
/* find the next segment */
seg = ptr;
while (!ISSEPNIL(*ptr)) ptr++;
while (!IS_SEP_OR_NIL(*ptr)) ptr++;
seglen = ptr - seg;
/* handle the segment */
@ -172,7 +173,7 @@ qse_size_t qse_canonpath (const qse_char_t* path, qse_char_t* canon, int flags)
while (tmp > non_root_start)
{
tmp--;
if (ISSEP(*tmp))
if (IS_SEP(*tmp))
{
tmp++; /* position it next to the separator */
break;
@ -233,7 +234,7 @@ qse_size_t qse_canonpath (const qse_char_t* path, qse_char_t* canon, int flags)
{
normal:
while (seg < ptr) *dst++ = *seg++;
if (ISSEP(*ptr))
if (IS_SEP(*ptr))
{
/* this segment ended with a separator */
*dst++ = *seg++; /* copy the separator */
@ -243,8 +244,8 @@ qse_size_t qse_canonpath (const qse_char_t* path, qse_char_t* canon, int flags)
}
while (1);
if (dst > non_root_start && ISSEP(dst[-1]) &&
((flags & QSE_CANONPATH_DROPTRAILINGSEP) || !ISSEP(ptr[-1])))
if (dst > non_root_start && IS_SEP(dst[-1]) &&
((flags & QSE_CANONPATH_DROPTRAILINGSEP) || !IS_SEP(ptr[-1])))
{
/* if the canoncal path composed so far ends with a separator
* and the original path didn't end with the separator, delete
@ -254,9 +255,9 @@ qse_size_t qse_canonpath (const qse_char_t* path, qse_char_t* canon, int flags)
* dst > non_root_start:
* there is at least 1 character after the root directory
* part.
* ISSEP(dst[-1]):
* IS_SEP(dst[-1]):
* the canonical path ends with a separator.
* ISSEP(ptr[-1]):
* IS_SEP(ptr[-1]):
* the origial path ends with a separator.
*/
dst[-1] = QSE_T('\0');
@ -303,17 +304,17 @@ qse_size_t qse_canonpath (const qse_char_t* path, qse_char_t* canon, int flags)
* the double slahses indicate a directory obviously */
if (canon[canon_len-3] == QSE_T('.') &&
canon[canon_len-2] == QSE_T('.') &&
ISSEP(canon[canon_len-1]))
IS_SEP(canon[canon_len-1]))
{
canon[--canon_len] = QSE_T('\0');
}
}
else if (canon_len > adj_base_len)
{
if (ISSEP(canon[canon_len-4]) &&
if (IS_SEP(canon[canon_len-4]) &&
canon[canon_len-3] == QSE_T('.') &&
canon[canon_len-2] == QSE_T('.') &&
ISSEP(canon[canon_len-1]))
IS_SEP(canon[canon_len-1]))
{
canon[--canon_len] = QSE_T('\0');
}

View File

@ -182,6 +182,7 @@ qse_size_t qse_mbs_setlen (qse_mbs_t* str, qse_size_t len)
}
while (str->val.len < len) str->val.ptr[str->val.len++] = QSE_MT(' ');
str->val.ptr[str->val.len] = QSE_MT('\0');
return str->val.len;
}

View File

@ -182,6 +182,7 @@ qse_size_t qse_wcs_setlen (qse_wcs_t* str, qse_size_t len)
}
while (str->val.len < len) str->val.ptr[str->val.len++] = QSE_WT(' ');
str->val.ptr[str->val.len] = QSE_WT('\0');
return str->val.len;
}

View File

@ -1,9 +1,9 @@
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# Makefile.in generated by automake 1.11.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
# Inc.
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@ -69,6 +69,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__uninstall_files_from_dir = { \
test -z "$$files" \
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
libqsenet_la_DEPENDENCIES =
@ -336,7 +342,7 @@ clean-libLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libqsenet.la: $(libqsenet_la_OBJECTS) $(libqsenet_la_DEPENDENCIES)
libqsenet.la: $(libqsenet_la_OBJECTS) $(libqsenet_la_DEPENDENCIES) $(EXTRA_libqsenet_la_DEPENDENCIES)
$(libqsenet_la_LINK) -rpath $(libdir) $(libqsenet_la_OBJECTS) $(libqsenet_la_LIBADD) $(LIBS)
mostlyclean-compile:
@ -481,10 +487,15 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:

View File

@ -1,9 +1,9 @@
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# Makefile.in generated by automake 1.11.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
# Inc.
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@ -70,6 +70,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__uninstall_files_from_dir = { \
test -z "$$files" \
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
libqsesed_la_DEPENDENCIES =
@ -344,9 +350,9 @@ clean-libLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libqsesed.la: $(libqsesed_la_OBJECTS) $(libqsesed_la_DEPENDENCIES)
libqsesed.la: $(libqsesed_la_OBJECTS) $(libqsesed_la_DEPENDENCIES) $(EXTRA_libqsesed_la_DEPENDENCIES)
$(libqsesed_la_LINK) -rpath $(libdir) $(libqsesed_la_OBJECTS) $(libqsesed_la_LIBADD) $(LIBS)
libqsesedxx.la: $(libqsesedxx_la_OBJECTS) $(libqsesedxx_la_DEPENDENCIES)
libqsesedxx.la: $(libqsesedxx_la_OBJECTS) $(libqsesedxx_la_DEPENDENCIES) $(EXTRA_libqsesedxx_la_DEPENDENCIES)
$(libqsesedxx_la_LINK) $(am_libqsesedxx_la_rpath) $(libqsesedxx_la_OBJECTS) $(libqsesedxx_la_LIBADD) $(LIBS)
mostlyclean-compile:
@ -508,10 +514,15 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:

View File

@ -1,9 +1,9 @@
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# Makefile.in generated by automake 1.11.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
# Inc.
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@ -69,6 +69,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__uninstall_files_from_dir = { \
test -z "$$files" \
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
libqsestx_la_DEPENDENCIES =
@ -326,7 +332,7 @@ clean-libLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libqsestx.la: $(libqsestx_la_OBJECTS) $(libqsestx_la_DEPENDENCIES)
libqsestx.la: $(libqsestx_la_OBJECTS) $(libqsestx_la_DEPENDENCIES) $(EXTRA_libqsestx_la_DEPENDENCIES)
$(libqsestx_la_LINK) -rpath $(libdir) $(libqsestx_la_OBJECTS) $(libqsestx_la_LIBADD) $(LIBS)
mostlyclean-compile:
@ -472,10 +478,15 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic: