11#include "helpers/datetime.h"
12#include "helpers/replace.h"
13#include "helpers/split.h"
37 if (fileEntry != NULL)
75 if (dirEntry != NULL && child != NULL)
84 while (nextChild->
next != NULL)
86 nextChild = nextChild->
next;
88 nextChild->
next = child;
125 if (dirEntry == NULL)
132 if (fileEntry == NULL)
140 if (fileEntry == NULL)
148 if (fileEntry == NULL)
156 if (subDirEntry == NULL)
164 if (fileEntry == NULL)
172 if (fileEntry == NULL)
180 if (subsubDirEntry == NULL)
189 if (fileEntry == NULL)
197 if (fileEntry == NULL)
227 split(path,
"/", &pathComponents);
231 for (
size_t index = 0; index < numComponents; index++)
234 if (strcmp(rootName, pathComponents.
strings[index]) != 0)
241 if ((index + 1) >= numComponents)
259 const char* childComponent = pathComponents.
strings[index + 1];
260 while (child != NULL)
263 if (strcmp(childName, childComponent) == 0)
294 char* filepath =
STRDUP(path);
295 if (filepath != NULL)
FileDirEntry * Composite_FileAccess_GetEntry(const char *path)
Return a FileDirEntry object representing the specified file "path" from an internal list of data ent...
DirEntry * _NewDirEntry(const char *name, time_t whenModified)
Create a new DirEntry object with the specified properties.
FileDirEntry * _NewFileEntry(const char *name, long length, time_t whenModified)
Create a new FileEntry object with the specified properties.
static void _ConstructTree(void)
Construct a file/directory tree with a predefined set of files and directories. If there are any out ...
void _AddChild(DirEntry *dirEntry, FileDirEntry *child)
Add a child to the given DirEntry object.
static FileDirEntry * _root
The root of the constructed file/directory tree.
static FileDirEntry * _FindEntry(char *path)
Search the file/directory "tree" for an entry that matches the given file "path". The file path is a ...
static void _DestroyTree(FileDirEntry *root)
Destroy a file/directory tree given its root. Each element of the hierarchical tree needs to be freed...
const char * FileDirEntry_GetName(FileDirEntry *entry)
Retrieve the name of the given FileDirEntry object.
FileDirEntry * FileDirEntry_GetChildren(FileDirEntry *entry)
Retrieve a pointer to the first child of the given FileDirEntry object. If the entry does not support...
@ FileDirType_Directory
Represents a directory entry that can contain other FileDirEntry components.
@ FileDirType_File
Represents a file entry.
Declaration of the Composite_FileAccess class used in the Composite Pattern.
Implementation of the FileDirEntry, FileEntry, and DirEntry classes used in the Composite Pattern.
time_t datetime_now(void)
Retrieve a time stamp that represents the current time.
void replace_chr(char *s, char c1, char c2)
Replace all occurrences of narrow character c1 with narrow character c2 in s, using case-sensitive se...
void SplitList_Clear(SplitList *list)
Clear the given SplitList object so it can be reused again. Releases the list of sub-strings (but doe...
void split(char *s, const char *splitChars, SplitList *components)
Split the given path into multiple strings based on the given delimiter. The pointers to each string ...
Declaration of the STRDUP macro that hides the differences between how strdup() is declared in differ...
#define STRDUP
Define STRDUP to be the operating system-specific version of strdup().
Represents a Directory entry.
FileDirEntry * _children
Linked list of possible children. NULL if empty.
FileDirEntry base
Base FileDirEntry identifying this entry.
Structure representing a File (FileEntry) or Directory (DirEntry) entry. This is included as the firs...
FileDirTypes fileDirType
Value from the FileDirTypes enumeration indicating what type of entry this is a part of....
const char * name
Name of this entry. Use the FileDirEntry_GetName() function to get this value.
struct FileDirEntry * next
Points to the next entry in a linked list of FileDirEntry objects. NULL means no more in list.
long length
Length of this entry. For DirEntry objects, this is computed when getting the length by calling the F...
time_t whenModified
Timestamp of when this entry was last "modified". Use the FileDirEntry_GetWhenModified() function to ...
FileDirEntry base
Base FileDirEntry identifying this entry.
Represents a collection of sub-strings split from a single string using the split() function.
size_t strings_count
Number of sub-strings.
const char ** strings
Pointers to each sub-string.