Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelheilmann committed Jan 22, 2018
1 parent 83242c1 commit f1286de
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 442 deletions.
88 changes: 0 additions & 88 deletions egolib/src/egolib/Platform/file_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

struct s_linux_find_context;
typedef struct s_linux_find_context linux_find_context_t;

//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

extern int sys_fs_init(const char *root_dir);

//--------------------------------------------------------------------------------------------
Expand All @@ -54,12 +48,6 @@ static char _dataPath[PATH_MAX] = EMPTY_CSTR;
static char _userPath[PATH_MAX] = EMPTY_CSTR;
static char _configPath[PATH_MAX] = EMPTY_CSTR;

struct s_linux_find_context
{
glob_t last_find;
size_t find_index;
};

int sys_fs_init(const char *root_dir)
{
// root_dir currently has no use in linux, since all of the egoboo game directories
Expand Down Expand Up @@ -119,82 +107,6 @@ int sys_fs_init(const char *root_dir)
return 0;
}

const char *fs_findFirstFile(const char *directory, const char *extension, fs_find_context_t *fs_search)
{
char pattern[PATH_MAX] = EMPTY_CSTR;

if (INVALID_CSTR(directory) || NULL == fs_search)
{
return NULL;
}
linux_find_context_t *pcnt = new linux_find_context_t();
fs_search->type = linux_find;
fs_search->ptr.l = pcnt;

if (extension) {
snprintf(pattern, PATH_MAX, "%s" SLASH_STR "*.%s", directory, extension);
} else {
snprintf(pattern, PATH_MAX, "%s" SLASH_STR "*", directory);
}

pcnt->last_find.gl_offs = 0;
glob(pattern, GLOB_NOSORT, NULL, &pcnt->last_find);
if (!pcnt->last_find.gl_pathc) {
return nullptr;
}
pcnt->find_index = 0;
char *last_slash = strrchr(pcnt->last_find.gl_pathv[pcnt->find_index], C_SLASH_CHR);
if (last_slash) {
return last_slash + 1;
}
return nullptr; /* should never happen */
}

const char *fs_findNextFile(fs_find_context_t *fs_search)
{
if (!fs_search || fs_search->type != linux_find)
{
return NULL;
}
linux_find_context_t *pcnt = fs_search->ptr.l;
if (!pcnt)
{
return NULL;
}

++pcnt->find_index;
if (pcnt->find_index >= pcnt->last_find.gl_pathc)
{
return NULL;
}
char *last_slash = strrchr(pcnt->last_find.gl_pathv[pcnt->find_index], C_SLASH_CHR);
if (last_slash)
{
return last_slash + 1;
}

return NULL; /* should never happen */
}

void fs_findClose(fs_find_context_t *fs_search)
{
if (NULL == fs_search || fs_search->type != linux_find)
{
return;
}
linux_find_context_t *pcnt = fs_search->ptr.l;
if (NULL == pcnt)
{
return;
}
globfree(&(pcnt->last_find));

delete pcnt;

fs_search->type = unknown_find;
fs_search->ptr.v = nullptr;
}

std::string fs_getDataDirectory()
{
return _dataPath;
Expand Down
126 changes: 0 additions & 126 deletions egolib/src/egolib/Platform/file_mac.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@

#include "egolib/file_common.h"

struct s_mac_find_context : Id::NonCopyable
{
NSDirectoryEnumerator *dirEnum;
NSString *dirEnumExtension;
NSString *dirEnumPath;
std::string currentFile;
};

static NSString *dataPath = nil;
static NSString *userPath = nil;
//static NSString *configPath = nil;

//---------------------------------------------------------------------------------------------
//File Routines-------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
int sys_fs_init(const char *root_path)
{
// JF> This function determines the temporary, import,
Expand Down Expand Up @@ -73,118 +62,3 @@ int sys_fs_init(const char *root_path)
{
return [dataPath UTF8String];
}

//---------------------------------------------------------------------------------------------
//Directory Functions--------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------

// Return the next file in the directory that matches the criteria specified in fs_findFirstFile
const char *fs_findNextFile(fs_find_context_t *fs_search)
{
@autoreleasepool {
NSString *fileName;
NSString *pathName;

if (fs_search == nullptr || fs_search->ptr.m == nullptr || fs_search->type != mac_find)
return nullptr;

s_mac_find_context *context = fs_search->ptr.m;

while (fileName = [context->dirEnum nextObject])
{
// Also, don't go down directories recursively.
pathName = [NSString stringWithFormat:@"%@/%@", context->dirEnumPath, fileName];
if (fs_fileIsDirectory([pathName UTF8String]))
{
[context->dirEnum skipDescendents];
}

if (context->dirEnumExtension != nil)
{
if ([[fileName pathExtension] isEqualToString: context->dirEnumExtension])
{
context->currentFile = [fileName UTF8String];
return context->currentFile.c_str();
}
}
else
{
context->currentFile = [fileName UTF8String];
return context->currentFile.c_str();
}
}

return nullptr;
}
}

// Stop the current find operation
void fs_findClose(fs_find_context_t *fs_search)
{
@autoreleasepool {
if (fs_search == nullptr || fs_search->ptr.m == nullptr || fs_search->type != mac_find)
return;

s_mac_find_context *context = fs_search->ptr.m;

[context->dirEnum release];
[context->dirEnumPath release];
[context->dirEnumExtension release];

delete context;

fs_search->type = unknown_find;
fs_search->ptr.v = nullptr;
}
}

// Begin enumerating files in a directory. The enumeration is not recursive; subdirectories
// won't be searched. If 'extension' is not nullptr, only files with the given extension will
// be returned.
const char *fs_findFirstFile(const char *path, const char *extension, fs_find_context_t *fs_search)
{
@autoreleasepool {
NSString *searchPath;

if (fs_search == nullptr)
return nullptr;

fs_search->type = mac_find;
fs_search->ptr.m = new s_mac_find_context();
if (fs_search->ptr.m == nullptr)
return nullptr;

s_mac_find_context *context = fs_search->ptr.m;

// If the path given is a relative one, we need to derive the full path
// for it by appending the current working directory
if (path[0] != '/')
{
searchPath = [[NSString alloc] initWithFormat:@"%@/%s", dataPath, path];
}
else
{
searchPath = [[NSString alloc] initWithUTF8String:path];
}

context->dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:searchPath];
if (context->dirEnum == nil)
{
[searchPath release];
delete context;
fs_search->type = unknown_find;
return nullptr;
}

[context->dirEnum retain];

if (extension != nullptr)
{
context->dirEnumExtension = [[NSString alloc] initWithUTF8String:extension];
}

context->dirEnumPath = searchPath;

return fs_findNextFile(fs_search);
}
}
92 changes: 0 additions & 92 deletions egolib/src/egolib/Platform/file_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

struct s_win32_find_context;
typedef struct s_win32_find_context win32_find_context_t;

//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

extern int sys_fs_init(const char *argv0);

//--------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -145,89 +139,3 @@ std::string fs_getConfigDirectory()
{
return _configPath;
}

//--------------------------------------------------------------------------------------------
// Directory Functions
//--------------------------------------------------------------------------------------------
struct s_win32_find_context
{
WIN32_FIND_DATA wfdData;
HANDLE hFind;
};

const char *fs_findFirstFile(const char *searchDir, const char *searchExtension, fs_find_context_t *fs_search)
{
char searchSpec[MAX_PATH] = EMPTY_CSTR;

if (INVALID_CSTR(searchDir) || !fs_search)
{
return nullptr;
}

win32_find_context_t *pcnt = new win32_find_context_t();
fs_search->type = win32_find;
fs_search->ptr.w = pcnt;

size_t len = strlen(searchDir) + 1;
if (C_SLASH_CHR != searchDir[len] || C_BACKSLASH_CHR != searchDir[len]) {
_snprintf(searchSpec, MAX_PATH, "%s" SLASH_STR, searchDir);
} else {
strncpy(searchSpec, searchDir, MAX_PATH);
}
if (nullptr != searchExtension) {
_snprintf(searchSpec, MAX_PATH, "%s*.%s", searchSpec, searchExtension);
} else {
strncat(searchSpec, "*", MAX_PATH);
}

pcnt->hFind = FindFirstFile( searchSpec, &pcnt->wfdData );
if (pcnt->hFind == INVALID_HANDLE_VALUE) {
return nullptr;
}

return pcnt->wfdData.cFileName;
}

const char *fs_findNextFile(fs_find_context_t *fs_search)
{
if (!fs_search || win32_find != fs_search->type)
{
return NULL;
}
win32_find_context_t *pcnt = fs_search->ptr.w;
if (!pcnt)
{
return NULL;
}
if (NULL == pcnt->hFind || INVALID_HANDLE_VALUE == pcnt->hFind)
{
return NULL;
}
if (!FindNextFile( pcnt->hFind, &pcnt->wfdData))
{
return NULL;
}
return pcnt->wfdData.cFileName;
}

void fs_findClose(fs_find_context_t *fs_search)
{
if (NULL == fs_search || win32_find != fs_search->type)
{
return;
}
win32_find_context_t *pcnt = fs_search->ptr.w;
if (NULL == pcnt)
{
return;
}
if (NULL != pcnt->hFind)
{
FindClose(pcnt->hFind);
pcnt->hFind = NULL;
}
delete pcnt;

fs_search->type = unknown_find;
fs_search->ptr.v = nullptr;
}
Loading

0 comments on commit f1286de

Please sign in to comment.