diff options
| author | oy <Tom_Adams@web.de> | 2010-09-29 00:53:53 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2010-09-29 00:53:53 +0200 |
| commit | aaf8e2bc8e02d37fb132c8acd7c2a8fe82c15117 (patch) | |
| tree | d8898339563b2dbbc4bc55f579c3b180cd1c435f /src/base | |
| parent | c172c24fd1fbf6a430e1852e62e72f6e0cfeeb63 (diff) | |
| download | zcatch-aaf8e2bc8e02d37fb132c8acd7c2a8fe82c15117.tar.gz zcatch-aaf8e2bc8e02d37fb132c8acd7c2a8fe82c15117.zip | |
cleaned up demo listing and fixed its sorting. Closes #73
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/system.c | 51 | ||||
| -rw-r--r-- | src/base/system.h | 18 |
2 files changed, 66 insertions, 3 deletions
diff --git a/src/base/system.c b/src/base/system.c index 6c74fb23..bf473650 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -869,6 +869,7 @@ int fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user) WIN32_FIND_DATA finddata; HANDLE handle; char buffer[1024*2]; + int length; str_format(buffer, sizeof(buffer), "%s/*", dir); handle = FindFirstFileA(buffer, &finddata); @@ -876,23 +877,36 @@ int fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user) if (handle == INVALID_HANDLE_VALUE) return 0; + str_format(buffer, sizeof(buffer), "%s/", dir); + length = str_length(buffer); + /* add all the entries */ do { - cb(finddata.cFileName, 0, type, user); - } while (FindNextFileA(handle, &finddata)); + str_copy(buffer+length, finddata.cFileName, (int)sizeof(buffer)-length); + cb(finddata.cFileName, fs_is_dir(buffer), type, user); + } + while (FindNextFileA(handle, &finddata)); FindClose(handle); return 0; #else struct dirent *entry; + char buffer[1024*2]; + int length; DIR *d = opendir(dir); if(!d) return 0; + str_format(buffer, sizeof(buffer), "%s/", dir); + length = str_length(buffer); + while((entry = readdir(d)) != NULL) - cb(entry->d_name, 0, type, user); + { + str_copy(buffer+length, entry->d_name, (int)sizeof(buffer)-length); + cb(entry->d_name, fs_is_dir(buffer), type, user); + } /* close the directory and return */ closedir(d); @@ -1155,6 +1169,37 @@ int str_comp_num(const char *a, const char *b, const int num) return strncmp(a, b, num); } +int str_comp_filenames(const char *a, const char *b) +{ + int result; + + for(; *a && *b; ++a, ++b) + { + if(*a >= '0' && *a <= '9' && *b >= '0' && *b <= '9') + { + result = 0; + do + { + if(!result) + result = *a - *b; + ++a; ++b; + } + while(*a >= '0' && *a <= '9' && *b >= '0' && *b <= '9'); + + if(*a >= '0' && *a <= '9') + return 1; + else if(*b >= '0' && *b <= '9') + return -1; + else if(result) + return result; + } + + if(*a != *b) + break; + } + return *a - *b; +} + const char *str_find_nocase(const char *haystack, const char *needle) { while(*haystack) /* native implementation */ diff --git a/src/base/system.h b/src/base/system.h index 2ef7a9f3..f71a03ec 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -830,6 +830,24 @@ int str_comp(const char *a, const char *b); int str_comp_num(const char *a, const char *b, const int num); /* + Function: str_comp_filenames + Compares two strings case sensitive, digit chars will be compared as numbers. + + Parameters: + a - String to compare. + b - String to compare. + + Returns: + <0 - String a is lesser then string b + 0 - String a is equal to string b + >0 - String a is greater then string b + + Remarks: + - The strings are treated as zero-termineted strings. +*/ +int str_comp_filenames(const char *a, const char *b); + +/* Function: str_find_nocase Finds a string inside another string case insensitive. |