#include <dir.h>
#endif
+#include "wx/setup.h"
+#ifdef HAVE_FNMATCH_H
+#include "fnmatch.h"
+#endif
+
#ifdef __WINDOWS__
#include "windows.h"
#endif
Add (copystring (token));
while (token)
{
- if ((token = strtok (NULL, PATH_TOKS)) != NULL)
+ if ((token = strtok ((char *) NULL, PATH_TOKS)) != NULL)
Add (wxString(token));
}
}
char *wxCopyAbsolutePath(const wxString& filename)
{
if (filename == "")
- return NULL;
+ return (char *) NULL;
if (! IsAbsolutePath(wxExpandPath(wxBuffer, filename))) {
char buf[_MAXPATHLEN];
#endif
{
register char *start = d;
- register braces = (*s == '{' || *s == '(');
+ register int braces = (*s == '{' || *s == '(');
register char *value;
while ((*d++ = *s))
if (braces ? (*s == '}' || *s == ')') : !(isalnum(*s) || *s == '_') )
static char dest[_MAXPATHLEN];
if (filename == "")
- return NULL;
+ return (char *) NULL;
strcpy (dest, WXSTRINGCAST filename);
#ifdef __WXMSW__
#endif
// Handle environment
- char *val = NULL;
- char *tcp = NULL;
- if (envname != NULL && (val = getenv (WXSTRINGCAST envname)) != NULL &&
+ char *val = (char *) NULL;
+ char *tcp = (char *) NULL;
+ if (envname != WXSTRINGCAST NULL && (val = getenv (WXSTRINGCAST envname)) != NULL &&
(tcp = strstr (dest, val)) != NULL)
{
strcpy (wxBuffer, tcp + strlen (val));
#endif
}
- return NULL;
+ return (char *) NULL;
}
// Return just the directory, or NULL if no directory
{
char *outfile = wxGetTempFileName("cat");
- FILE *fp1 = NULL;
- FILE *fp2 = NULL;
- FILE *fp3 = NULL;
+ FILE *fp1 = (FILE *) NULL;
+ FILE *fp2 = (FILE *) NULL;
+ FILE *fp3 = (FILE *) NULL;
// Open the inputs and outputs
if ((fp1 = fopen (WXSTRINGCAST file1, "rb")) == NULL ||
(fp2 = fopen (WXSTRINGCAST file2, "rb")) == NULL ||
}
cerr << _("wxWindows: error finding temporary file name.\n");
if (buf) buf[0] = 0;
- return NULL;
+ return (char *) NULL;
#endif
}
// Flags are reserved for future use.
#ifndef __VMS__
-static DIR *wxDirStream = NULL;
-static char *wxFileSpec = NULL;
+static DIR *wxDirStream = (DIR *) NULL;
+static char *wxFileSpec = (char *) NULL;
static int wxFindFileFlags = 0;
#endif
p = ".";
if ((wxDirStream=opendir(p))==NULL)
- return NULL;
+ return (char *) NULL;
/* MATTHEW: [5] wxFindNextFile can do the rest of the work */
return wxFindNextFile();
#endif
// ifndef __VMS__
- return NULL;
+ return (char *) NULL;
}
char *wxFindNextFile(void)
/* MATTHEW: [2] Don't crash if we read too many times */
if (!wxDirStream)
- return NULL;
+ return (char *) NULL;
// Find path only so we can concatenate
// found file onto path
}
}
closedir(wxDirStream);
- wxDirStream = NULL;
+ wxDirStream = (DIR *) NULL;
#endif
// ifndef __VMS__
- return NULL;
+ return (char *) NULL;
}
#elif defined(__WXMSW__)
wxString strFile;
char *pc;
- for ( pc = strtok(szPath, PATH_SEP); pc; pc = strtok(NULL, PATH_SEP) ) {
+ for ( pc = strtok(szPath, PATH_SEP); pc; pc = strtok((char *) NULL, PATH_SEP) ) {
// search for the file in this directory
strFile = pc;
if ( !wxEndsWithPathSeparator(pc) )
const char *pSepDos = strrchr(pszFileName, FILE_SEP_PATH_DOS);
// take the last of the two
- uint nPosUnix = pSepUnix ? pSepUnix - pszFileName : 0;
- uint nPosDos = pSepDos ? pSepDos - pszFileName : 0;
+ size_t nPosUnix = pSepUnix ? pSepUnix - pszFileName : 0;
+ size_t nPosDos = pSepDos ? pSepDos - pszFileName : 0;
if ( nPosDos > nPosUnix )
nPosUnix = nPosDos;
-// uint nLen = Strlen(pszFileName);
+// size_t nLen = Strlen(pszFileName);
if ( pstrPath )
*pstrPath = wxString(pszFileName, nPosUnix);
if ( pDot ) {
- uint nPosDot = pDot - pszFileName;
+ size_t nPosDot = pDot - pszFileName;
if ( pstrName )
*pstrName = wxString(pszFileName + nPosUnix + 1, nPosDot - nPosUnix);
if ( pstrExt )
pstrExt->Empty();
}
}
+
+//------------------------------------------------------------------------
+// wild character routines
+//------------------------------------------------------------------------
+
+bool wxIsWild( const wxString& pattern )
+{
+ wxString tmp = pattern;
+ char *pat = WXSTRINGCAST(tmp);
+ while (*pat) {
+ switch (*pat++) {
+ case '?': case '*': case '[': case '{':
+ return TRUE;
+ case '\\':
+ if (!*pat++)
+ return FALSE;
+ }
+ }
+ return FALSE;
+};
+
+
+#ifdef HAVE_FNMATCH_H
+{
+ // dot_special: what is it supposed to do?
+ return fnmatch(pat.c_str(), text.c_str(), FNM_PERIOD) == 0;
+}
+#else
+
+#pragma error Broken implementation of wxMatchWild() -- needs fixing!
+ /*
+ * WARNING: this code is broken!
+ */
+bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special )
+{
+ wxString tmp1 = pat;
+ char *pattern = WXSTRINGCAST(tmp1);
+ wxString tmp2 = text;
+ char *str = WXSTRINGCAST(tmp2);
+ char c;
+ char *cp;
+ bool done = FALSE, ret_code, ok;
+ // Below is for vi fans
+ const char OB = '{', CB = '}';
+
+ // dot_special means '.' only matches '.'
+ if (dot_special && *str == '.' && *pattern != *str)
+ return FALSE;
+
+ while ((*pattern != '\0') && (!done)
+ && (((*str=='\0')&&((*pattern==OB)||(*pattern=='*')))||(*str!='\0'))) {
+ switch (*pattern) {
+ case '\\':
+ pattern++;
+ if (*pattern != '\0')
+ pattern++;
+ break;
+ case '*':
+ pattern++;
+ ret_code = FALSE;
+ while ((*str!='\0')
+ && (!(ret_code=wxMatchWild(pattern, str++, FALSE))))
+ /*loop*/;
+ if (ret_code) {
+ while (*str != '\0')
+ str++;
+ while (*pattern != '\0')
+ pattern++;
+ }
+ break;
+ case '[':
+ pattern++;
+ repeat:
+ if ((*pattern == '\0') || (*pattern == ']')) {
+ done = TRUE;
+ break;
+ }
+ if (*pattern == '\\') {
+ pattern++;
+ if (*pattern == '\0') {
+ done = TRUE;
+ break;
+ }
+ }
+ if (*(pattern + 1) == '-') {
+ c = *pattern;
+ pattern += 2;
+ if (*pattern == ']') {
+ done = TRUE;
+ break;
+ }
+ if (*pattern == '\\') {
+ pattern++;
+ if (*pattern == '\0') {
+ done = TRUE;
+ break;
+ }
+ }
+ if ((*str < c) || (*str > *pattern)) {
+ pattern++;
+ goto repeat;
+ }
+ } else if (*pattern != *str) {
+ pattern++;
+ goto repeat;
+ }
+ pattern++;
+ while ((*pattern != ']') && (*pattern != '\0')) {
+ if ((*pattern == '\\') && (*(pattern + 1) != '\0'))
+ pattern++;
+ pattern++;
+ }
+ if (*pattern != '\0') {
+ pattern++, str++;
+ }
+ break;
+ case '?':
+ pattern++;
+ str++;
+ break;
+ case OB:
+ pattern++;
+ while ((*pattern != CB) && (*pattern != '\0')) {
+ cp = str;
+ ok = TRUE;
+ while (ok && (*cp != '\0') && (*pattern != '\0')
+ && (*pattern != ',') && (*pattern != CB)) {
+ if (*pattern == '\\')
+ pattern++;
+ ok = (*pattern++ == *cp++);
+ }
+ if (*pattern == '\0') {
+ ok = FALSE;
+ done = TRUE;
+ break;
+ } else if (ok) {
+ str = cp;
+ while ((*pattern != CB) && (*pattern != '\0')) {
+ if (*++pattern == '\\') {
+ if (*++pattern == CB)
+ pattern++;
+ }
+ }
+ } else {
+ while (*pattern!=CB && *pattern!=',' && *pattern!='\0') {
+ if (*++pattern == '\\') {
+ if (*++pattern == CB || *pattern == ',')
+ pattern++;
+ }
+ }
+ }
+ if (*pattern != '\0')
+ pattern++;
+ }
+ break;
+ default:
+ if (*str == *pattern) {
+ str++, pattern++;
+ } else {
+ done = TRUE;
+ }
+ }
+ }
+ while (*pattern == '*')
+ pattern++;
+ return ((*str == '\0') && (*pattern == '\0'));
+};
+#endif
+