reset();
}
-FileItem::FileItem(char *path, char *name, int is_dir,
- int64_t size, int month, int day, int year,
- int64_t calendar_time, int item_no)
+FileItem::FileItem(const char *path, const char *name, int is_dir,
+ int64_t size, time_t mtime, int item_no)
{
this->path = new char[strlen(path)];
this->name = new char[strlen(name)];
if(this->name) strcpy(this->name, name);
this->is_dir = is_dir;
this->size = size;
- this->month = month;
- this->day = day;
- this->year = year;
- this->calendar_time = calendar_time;
+ this->mtime = mtime;
this->item_no = item_no;
}
name = 0;
is_dir = 0;
size = 0;
- month = 0;
- day = 0;
- year = 0;
- calendar_time = 0;
+ mtime = 0;
item_no = -1;
return 0;
}
{
FileItem *item1 = *(FileItem**)ptr1;
FileItem *item2 = *(FileItem**)ptr2;
- return item1->calendar_time == item2->calendar_time ?
+ return item1->mtime == item2->mtime ?
item1->item_no - item2->item_no :
- item1->calendar_time > item2->calendar_time;
+ item1->mtime > item2->mtime;
}
int FileSystem::date_descending(const void *ptr1, const void *ptr2)
{
FileItem *item1 = *(FileItem**)ptr1;
FileItem *item2 = *(FileItem**)ptr2;
- return item2->calendar_time == item1->calendar_time ?
+ return item2->mtime == item1->mtime ?
item2->item_no - item1->item_no :
- item2->calendar_time > item1->calendar_time;
+ item2->mtime > item1->mtime;
}
int FileSystem::ext_ascending(const void *ptr1, const void *ptr2)
return 0;
}
-int FileSystem::test_filter(FileItem *file)
+int FileSystem::test_filter(const char *url, const char *filter)
{
- char *filter1 = 0, *filter2 = filter, *subfilter1, *subfilter2;
- int result = 0;
- int done = 0, token_done;
- int token_number = 0;
-
-// Don't filter directories
- if(file->is_dir) return 0;
+ char string[BCTEXTLEN], string2[BCTEXTLEN];
+ const char *filter1 = 0, *filter2 = filter;
+ int done = 0, result = 0, token_number = 0;
-// Empty filename string
- if(!file->name) return 1;
-
- do
- {
-// Get next token
+ do { // Get next token
filter1 = strchr(filter2, '[');
string[0] = 0;
-
-// Get next filter
- if(filter1)
- {
- filter1++;
- filter2 = strchr(filter1, ']');
-
- if(filter2)
- {
- int i;
- for(i = 0; filter1 + i < filter2; i++)
- string[i] = filter1[i];
- string[i] = 0;
+ if( filter1 ) { // Get next filter
+ filter2 = strchr(++filter1, ']');
+ if( filter2 ) {
+ int n = filter2 - filter1;
+ for( int i=0; i<n; ++i ) string[i] = filter1[i];
+ string[n] = 0;
}
- else
- {
+ else {
strcpy(string, filter1);
done = 1;
}
}
- else
- {
- if(!token_number)
+ else {
+ if( !token_number )
strcpy(string, filter);
else
done = 1;
}
-// Process the token
- if(string[0] != 0)
- {
- char *path = file->name;
- subfilter1 = string;
- token_done = 0;
+ if( string[0] ) { // Process the token
+ const char *path = url;
+ const char *subfilter1 = string, *subfilter2 = 0;
+ int token_done = 0;
result = 0;
-
- do
- {
+ do {
string2[0] = 0;
subfilter2 = strchr(subfilter1, '*');
-
- if(subfilter2)
- {
- int i;
- for(i = 0; subfilter1 + i < subfilter2; i++)
- string2[i] = subfilter1[i];
-
- string2[i] = 0;
+ if( subfilter2 ) {
+ int n = subfilter2 - subfilter1;
+ for( int i=0; i<n; ++i ) string2[i] = subfilter1[i];
+ string2[n] = 0;
}
- else
- {
+ else {
strcpy(string2, subfilter1);
token_done = 1;
}
- if(string2[0] != 0)
- {
-// Subfilter must exist at some later point in the string
- if(subfilter1 > string)
- {
- if(!strstr(path, string2))
- {
- result = 1;
- token_done = 1;
- }
+ if( string2[0] ) { // Subfilter exists
+ if( subfilter1 > string ) {
+ const char *cp = strstr(path, string2);
+ if( !cp )
+ result = token_done = 1;
else
- path = strstr(path, string2) + strlen(string2);
+ path = cp + strlen(string2);
}
- else
-// Subfilter must exist at this point in the string
- {
- if(strncmp(path, string2, strlen(string2)))
-// if(strncasecmp(path, string2, strlen(string2)))
- {
- result = 1;
- token_done = 1;
- }
+ else { // Subfilter exists
+ if( strncmp(path, string2, strlen(string2)) ) // strncasecmp?
+ result = token_done = 1;
else
- path += strlen(string2);
+ path += strlen(string2);
}
// String must terminate after subfilter
- if(!subfilter2)
- {
- if(*path != 0)
- {
- result = 1;
- token_done = 1;
- }
+ if( !subfilter2 ) {
+ if( *path )
+ result = token_done = 1;
}
}
subfilter1 = subfilter2 + 1;
// Let pass if no subfilter
- }while(!token_done && !result);
+ } while( !token_done && !result );
}
- token_number++;
- }while(!done && result);
+ ++token_number;
+ } while( !done && result );
return result;
}
+int FileSystem::test_filter(FileItem *file)
+{
+// Don't filter directories
+ if( file->is_dir ) return 0;
+ if( !file->name ) return 1;
+ return test_filter(file->name, this->filter);
+}
int FileSystem::scan_directory(const char *new_dir)
{
if(!stat(full_path, &ostat))
{
new_file->size = ostat.st_size;
- struct tm *mod_time = localtime(&(ostat.st_mtime));
- new_file->month = mod_time->tm_mon + 1;
- new_file->day = mod_time->tm_mday;
- new_file->year = mod_time->tm_year + 1900;
- new_file->calendar_time = ostat.st_mtime;
+ new_file->mtime = ostat.st_mtime;
if(S_ISDIR(ostat.st_mode))
{
char new_dir[BCTEXTLEN];
strcpy(new_dir, new_dir_);
complete_path(new_dir);
-
- mkdir(new_dir, S_IREAD | S_IWRITE | S_IEXEC);
- return 0;
+ return mkdir(new_dir, S_IRWXU | S_IRWXG | S_IRWXO);
}
int FileSystem::parse_tildas(char *new_dir)