Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

dirtree.h File Reference

#include "vfile.h"

Go to the source code of this file.

Typedefs

typedef DirTree DirTree
typedef DirTree_Finder DirTree_Finder

Functions

DirTreeDirTree_Create (void)
DirTreeDirTree_CreateFromFile (geVFile *File)
geBoolean DirTree_WriteToFile (const DirTree *Tree, geVFile *File)
geBoolean DirTree_GetSize (const DirTree *Tree, long *Size)
void DirTree_Destroy (DirTree *Tree)
DirTreeDirTree_FindExact (const DirTree *Tree, const char *Path)
DirTreeDirTree_FindPartial (const DirTree *Tree, const char *Path, const char **LeftOvers)
DirTreeDirTree_AddFile (DirTree *Tree, const char *Path, geBoolean IsDirectory)
geBoolean DirTree_Remove (DirTree *Tree, DirTree *SubTree)
void DirTree_SetFileAttributes (DirTree *Tree, geVFile_Attributes Attributes)
void DirTree_GetFileAttributes (DirTree *Tree, geVFile_Attributes *Attributes)
void DirTree_SetFileOffset (DirTree *Tree, long Offset)
void DirTree_GetFileOffset (DirTree *Tree, long *Offset)
void DirTree_SetFileTime (DirTree *Tree, const geVFile_Time *Time)
void DirTree_GetFileTime (DirTree *Tree, geVFile_Time *Time)
void DirTree_SetFileSize (DirTree *Tree, long Size)
void DirTree_GetFileSize (DirTree *Tree, long *Size)
geBoolean DirTree_SetFileHints (DirTree *Tree, const geVFile_Hints *Hints)
void DirTree_GetFileHints (DirTree *Tree, geVFile_Hints *Hints)
geBoolean DirTree_GetName (DirTree *Tree, char *Buff, int MaxLen)
geBoolean DirTree_FileExists (const DirTree *Tree, const char *Path)
DirTree_FinderDirTree_CreateFinder (DirTree *Tree, const char *Path)
void DirTree_DestroyFinder (DirTree_Finder *Finder)
DirTreeDirTree_FinderGetNextFile (DirTree_Finder *Finder)


Typedef Documentation

typedef struct DirTree DirTree
 

Definition at line 27 of file dirtree.h.

typedef struct DirTree_Finder DirTree_Finder
 

Definition at line 28 of file dirtree.h.


Function Documentation

DirTree* DirTree_AddFile DirTree Tree,
const char *  Path,
geBoolean  IsDirectory
 

Definition at line 436 of file dirtree.c.

References DirTree::AttributeFlags, DirTree::Children, DirTree, DirTree_FindPartial(), DuplicateString(), GE_FALSE, GE_TRUE, GE_VFILE_ATTRIB_DIRECTORY, geRam_Allocate, geRam_Free, DirTree::Name, NULL, PathHasDir(), and DirTree::Siblings.

Referenced by FSVFS_Open().

00437 {
00438         DirTree *               NewEntry;
00439         const char *    LeftOvers;
00440 
00441         assert(Tree);
00442         assert(Path);
00443         assert(IsDirectory == GE_TRUE || IsDirectory == GE_FALSE);
00444 
00445         assert(strlen(Path) > 0);
00446 
00447         if      (PathHasDir(Path))
00448         {
00449                 Tree = DirTree_FindPartial(Tree, Path, &LeftOvers);
00450                 if      (!Tree)
00451                         return NULL;
00452         
00453                 if      (PathHasDir(LeftOvers))
00454                         return NULL;
00455         
00456                 Path = LeftOvers;
00457         }
00458 
00459         NewEntry = geRam_Allocate(sizeof(*NewEntry));
00460         if      (!NewEntry)
00461                 return NULL;
00462 
00463         memset(NewEntry, 0, sizeof(*NewEntry));
00464         NewEntry->Name = DuplicateString(Path);
00465         if      (!NewEntry->Name)
00466         {
00467                 geRam_Free(NewEntry->Name);
00468                 geRam_Free(NewEntry);
00469                 return NULL;
00470         }
00471 
00472         NewEntry->Siblings = Tree->Children;
00473                                                  Tree->Children = NewEntry;
00474 
00475         if      (IsDirectory == GE_TRUE)
00476                 NewEntry->AttributeFlags |= GE_VFILE_ATTRIB_DIRECTORY;
00477 
00478         return NewEntry;
00479 }

DirTree* DirTree_Create void   ) 
 

Definition at line 58 of file dirtree.c.

References DirTree::AttributeFlags, DirTree, DuplicateString(), GE_VFILE_ATTRIB_DIRECTORY, geRam_Allocate, geRam_Free, DirTree::Name, and NULL.

Referenced by FSVFS_OpenNewSystem().

00059 {
00060         DirTree *       Tree;
00061 
00062         Tree = geRam_Allocate(sizeof(*Tree));
00063         if      (!Tree)
00064                 return Tree;
00065 
00066         memset(Tree, 0, sizeof(*Tree));
00067         Tree->Name = DuplicateString("");
00068         if      (!Tree->Name)
00069         {
00070                 geRam_Free(Tree);
00071                 return NULL;
00072         }
00073 
00074         Tree->AttributeFlags |= GE_VFILE_ATTRIB_DIRECTORY;
00075 
00076         return Tree;
00077 }

DirTree_Finder* DirTree_CreateFinder DirTree Tree,
const char *  Path
 

Definition at line 617 of file dirtree.c.

References DirTree::Children, DirTree_Finder::Current, DirTree, DirTree_FindExact(), DuplicateString(), geRam_Allocate, geRam_Free, DirTree_Finder::MatchExt, DirTree_Finder::MatchName, and NULL.

Referenced by FSVFS_FinderCreate().

00618 {
00619         DirTree_Finder *        Finder;
00620         DirTree *                       SubTree;
00621         char                            Directory[_MAX_PATH];
00622         char                            Name[_MAX_FNAME];
00623         char                            Ext[_MAX_EXT];
00624 
00625         assert(Tree);
00626         assert(Path);
00627 
00628         _splitpath(Path, NULL, Directory, Name, Ext);
00629 
00630         SubTree = DirTree_FindExact(Tree, Directory);
00631         if      (!SubTree)
00632                 return NULL;
00633 
00634         Finder = geRam_Allocate(sizeof(*Finder));
00635         if      (!Finder)
00636                 return Finder;
00637 
00638         Finder->MatchName = DuplicateString(Name);
00639         if      (!Finder->MatchName)
00640         {
00641                 geRam_Free(Finder);
00642                 return NULL;
00643         }
00644 
00645         // The RTL leaves the '.' on there.  That won't do.
00646         if      (*Ext == '.')
00647                 Finder->MatchExt = DuplicateString(&Ext[1]);
00648         else
00649                 Finder->MatchExt = DuplicateString(&Ext[0]);
00650 
00651         if      (!Finder->MatchExt)
00652         {
00653                 geRam_Free(Finder->MatchName);
00654                 geRam_Free(Finder);
00655                 return NULL;
00656         }
00657 
00658         Finder->Current = SubTree->Children;
00659 
00660         return Finder;
00661 }

DirTree* DirTree_CreateFromFile geVFile File  ) 
 

Definition at line 339 of file dirtree.c.

References DirTree, DirTree_Destroy(), DIRTREE_FILE_SIGNATURE, GE_FALSE, geVFile_Read(), geVFile_Tell(), NULL, ReadTree(), DirTree_Header::Signature, and DirTree_Header::Size.

Referenced by FSVFS_OpenNewSystem().

00340 {
00341         DirTree *               Res;
00342         DirTree_Header  Header;
00343         long                    StartPosition;
00344         long                    EndPosition;
00345         
00346         if      (geVFile_Tell(File, &StartPosition) == GE_FALSE)
00347                 return GE_FALSE;
00348 
00349         if      (geVFile_Read(File, &Header, sizeof(Header)) == GE_FALSE)
00350                 return NULL;
00351 
00352         if      (Header.Signature != DIRTREE_FILE_SIGNATURE)
00353                 return GE_FALSE;
00354 
00355         if      (ReadTree(File, &Res) == GE_FALSE)
00356                 return NULL;
00357 
00358         geVFile_Tell(File, &EndPosition);
00359         if      (Header.Size != EndPosition - StartPosition)
00360         {
00361                 DirTree_Destroy(Res);
00362                 return NULL;
00363         }
00364 
00365         return Res;
00366 }

void DirTree_Destroy DirTree Tree  ) 
 

Definition at line 79 of file dirtree.c.

References DirTree::Children, geRam_Free, DirTree::Name, and DirTree::Siblings.

Referenced by DirTree_CreateFromFile(), DirTree_Remove(), FSVFS_Close(), FSVFS_OpenNewSystem(), and ReadTree().

00080 {
00081         assert(Tree);
00082         assert(Tree->Name);
00083 
00084         if      (Tree->Children)
00085                 DirTree_Destroy(Tree->Children);
00086 
00087         if      (Tree->Siblings)
00088                 DirTree_Destroy(Tree->Siblings);
00089 
00090         geRam_Free(Tree->Name);
00091         geRam_Free(Tree);
00092 }

void DirTree_DestroyFinder DirTree_Finder Finder  ) 
 

Definition at line 663 of file dirtree.c.

References geRam_Free, DirTree_Finder::MatchExt, and DirTree_Finder::MatchName.

Referenced by FSVFS_FinderDestroy().

00664 {
00665         assert(Finder);
00666         assert(Finder->MatchName);
00667         assert(Finder->MatchExt);
00668 
00669         geRam_Free(Finder->MatchName);
00670         geRam_Free(Finder->MatchExt);
00671         geRam_Free(Finder);
00672 }

geBoolean DirTree_FileExists const DirTree Tree,
const char *  Path
 

Definition at line 609 of file dirtree.c.

References DirTree_FindExact(), GE_FALSE, GE_TRUE, geBoolean, and NULL.

Referenced by FSVFS_FileExists().

00610 {
00611         if      (DirTree_FindExact(Tree, Path) == NULL)
00612                 return GE_FALSE;
00613 
00614         return GE_TRUE;
00615 }

DirTree* DirTree_FinderGetNextFile DirTree_Finder Finder  ) 
 

Definition at line 674 of file dirtree.c.

References DirTree_Finder::Current, DirTree, GE_TRUE, DirTree_Finder::MatchExt, DirTree_Finder::MatchName, MatchPattern(), DirTree::Name, NULL, and DirTree::Siblings.

Referenced by FSVFS_FinderGetNextFile().

00675 {
00676         DirTree *       Res;
00677         char            Name[_MAX_FNAME];
00678         char            Ext[_MAX_EXT];
00679 
00680         assert(Finder);
00681 
00682         Res = Finder->Current;
00683 
00684         if      (!Res)
00685                 return Res;
00686 
00687         do
00688         {
00689                 _splitpath(Res->Name, NULL, NULL, Name, Ext);
00690                 if      (MatchPattern(Name, Finder->MatchName) == GE_TRUE &&
00691                          MatchPattern(Ext,  Finder->MatchExt) == GE_TRUE)
00692                 {
00693                         break;
00694                 }
00695 
00696                 Res = Res->Siblings;
00697 
00698         }       while   (Res);
00699 
00700         if      (Res)
00701                 Finder->Current = Res->Siblings;
00702 
00703         return Res;
00704 }

DirTree* DirTree_FindExact const DirTree Tree,
const char *  Path
 

Definition at line 368 of file dirtree.c.

References DirTree::Children, DirTree, GetNextDir(), DirTree::Name, NULL, and DirTree::Siblings.

Referenced by DirTree_CreateFinder(), DirTree_FileExists(), and FSVFS_Open().

00369 {
00370         static char     Buff[_MAX_PATH];
00371         DirTree *       Siblings;
00372 
00373         assert(Tree);
00374         assert(Path);
00375 
00376         if      (*Path == '\\')
00377                 return NULL;
00378 
00379         if      (*Path == '\0')
00380                 return (DirTree *)Tree;
00381 
00382         Path = GetNextDir(Path, Buff);
00383 
00384         Siblings = Tree->Children;
00385         while   (Siblings)
00386         {
00387                 if      (!stricmp(Siblings->Name, Buff))
00388                 {
00389                         if      (!*Path)
00390                                 return Siblings;
00391                         return DirTree_FindExact(Siblings, Path);
00392                 }
00393                 Siblings = Siblings->Siblings;
00394         }
00395 
00396         return NULL;
00397 }

DirTree* DirTree_FindPartial const DirTree Tree,
const char *  Path,
const char **  LeftOvers
 

Definition at line 399 of file dirtree.c.

References DirTree::Children, DirTree, GetNextDir(), DirTree::Name, NULL, and DirTree::Siblings.

Referenced by DirTree_AddFile().

00403 {
00404         static char     Buff[_MAX_PATH];
00405         DirTree *       Siblings;
00406 
00407         assert(Tree);
00408         assert(Path);
00409 
00410         if      (*Path == '\\')
00411                 return NULL;
00412 
00413         *LeftOvers = Path;
00414 
00415         if      (*Path == '\0')
00416                 return (DirTree *)Tree;
00417 
00418         Path = GetNextDir(Path, Buff);
00419 
00420         Siblings = Tree->Children;
00421         while   (Siblings)
00422         {
00423                 if      (!stricmp(Siblings->Name, Buff))
00424                 {
00425                         *LeftOvers = Path;
00426                         if      (!*Path)
00427                                 return Siblings;
00428                         return DirTree_FindPartial(Siblings, Path, LeftOvers);
00429                 }
00430                 Siblings = Siblings->Siblings;
00431         }
00432 
00433         return (DirTree *)Tree;
00434 }

void DirTree_GetFileAttributes DirTree Tree,
geVFile_Attributes Attributes
 

Definition at line 533 of file dirtree.c.

References DirTree::AttributeFlags.

Referenced by FSVFS_FinderGetProperties(), and FSVFS_GetProperties().

00534 {
00535         assert(Tree);
00536         assert(Attributes);
00537 
00538         *Attributes = Tree->AttributeFlags;
00539 }

void DirTree_GetFileHints DirTree Tree,
geVFile_Hints Hints
 

Definition at line 587 of file dirtree.c.

References DirTree::Hints.

Referenced by FSVFS_FinderGetProperties(), and FSVFS_GetProperties().

00588 {
00589         *Hints = Tree->Hints;
00590 }

void DirTree_GetFileOffset DirTree Tree,
long *  Offset
 

Definition at line 549 of file dirtree.c.

References DirTree::AttributeFlags, GE_VFILE_ATTRIB_DIRECTORY, and DirTree::Offset.

Referenced by FSVFS_Open().

00550 {
00551         assert(Leaf);
00552         assert(!(Leaf->AttributeFlags & GE_VFILE_ATTRIB_DIRECTORY));
00553 
00554         *Offset = Leaf->Offset;
00555 }

void DirTree_GetFileSize DirTree Tree,
long *  Size
 

Definition at line 200 of file dirtree.c.

References DirTree::Size.

Referenced by FSVFS_FinderGetProperties(), FSVFS_GetProperties(), and FSVFS_Open().

00201 {
00202         assert(Tree);
00203         *Size = Tree->Size;
00204 }

void DirTree_GetFileTime DirTree Tree,
geVFile_Time Time
 

Definition at line 564 of file dirtree.c.

References DirTree::Time.

Referenced by FSVFS_FinderGetProperties(), and FSVFS_GetProperties().

00565 {
00566         assert(Tree);
00567 
00568         *Time = Tree->Time;
00569 }

geBoolean DirTree_GetName DirTree Tree,
char *  Buff,
int  MaxLen
 

Definition at line 592 of file dirtree.c.

References GE_FALSE, GE_TRUE, geBoolean, and DirTree::Name.

Referenced by FSVFS_FinderGetProperties(), and FSVFS_GetProperties().

00593 {
00594         int     Length;
00595 
00596         assert(Tree);
00597         assert(Buff);
00598         assert(MaxLen > 0);
00599 
00600         Length = strlen(Tree->Name);
00601         if      (Length > MaxLen)
00602                 return GE_FALSE;
00603 
00604         memcpy(Buff, Tree->Name, Length + 1);
00605 
00606         return GE_TRUE;
00607 }

geBoolean DirTree_GetSize const DirTree Tree,
long *  Size
 

Definition at line 218 of file dirtree.c.

References geVFile_MemoryContext::Data, geVFile_MemoryContext::DataLength, DirTree_WriteToFile1(), GE_FALSE, GE_TRUE, GE_VFILE_OPEN_CREATE, GE_VFILE_TYPE_MEMORY, geBoolean, geVFile_Close(), geVFile_OpenNewSystem(), geVFile_Size(), and NULL.

00219 {
00220         geVFile *                               FS;
00221         geVFile_MemoryContext   Context;
00222 
00223         /*
00224                 This function is implemented via a write to a memory file for
00225                 a few reasons.  First, it makes it easier to maintain this code.  We
00226                 don't have to track format information in Write, Read and Size functions,
00227                 just in Write and Read.  Second, it gets us testing of the memory
00228                 file system for free.  Third, it was cute.  The last one doesn't count,
00229                 of course, but the other two are compelling.  This API ends up being
00230                 inefficient, but the assumption is that it will be called rarely.
00231         */
00232 
00233         Context.Data       = NULL;
00234         Context.DataLength = 0;
00235 
00236         FS = geVFile_OpenNewSystem(NULL,
00237                                                          GE_VFILE_TYPE_MEMORY,
00238                                                          NULL,
00239                                                          &Context,
00240                                                          GE_VFILE_OPEN_CREATE);
00241         if      (!FS)
00242                 return GE_FALSE;
00243 
00244         if      (DirTree_WriteToFile1(Tree, FS, Size) == GE_FALSE)
00245                 return GE_FALSE;
00246 
00247         if      (geVFile_Size(FS, Size) == GE_FALSE)
00248                 return GE_FALSE;
00249 
00250         geVFile_Close(FS);
00251 
00252         return GE_TRUE;
00253 }

geBoolean DirTree_Remove DirTree Tree,
DirTree SubTree
 

Definition at line 481 of file dirtree.c.

References DirTree::Children, DirTree, DirTree_Destroy(), GE_FALSE, GE_TRUE, geBoolean, NULL, DirTree::Parent, and DirTree::Siblings.

00482 {
00483         DirTree         Siblings;
00484         DirTree *       pSiblings;
00485         DirTree *       Parent;
00486         DirTree *       ParanoiaCheck;
00487 
00488         assert(Tree);
00489         assert(SubTree);
00490 
00491         Parent = SubTree->Parent;
00492         assert(Parent);
00493 
00494         ParanoiaCheck = Parent;
00495         while   (ParanoiaCheck && ParanoiaCheck != Tree)
00496                 ParanoiaCheck = ParanoiaCheck->Parent;
00497         if      (!ParanoiaCheck)
00498                 return GE_FALSE;
00499 
00500         Siblings.Siblings = Parent->Children;
00501         assert(Siblings.Siblings);
00502         pSiblings = &Siblings;
00503         while   (pSiblings->Siblings)
00504         {
00505                 if      (pSiblings->Siblings == SubTree)
00506                 {
00507                         pSiblings->Siblings = SubTree->Siblings;
00508                         if      (SubTree == Parent->Children)
00509                                 Parent->Children = SubTree->Siblings;
00510                         SubTree->Siblings = NULL;
00511                         DirTree_Destroy(SubTree);
00512                         return GE_TRUE;
00513                 }
00514                 pSiblings = pSiblings->Siblings;
00515         }
00516 
00517         assert(!"Shouldn't be a way to get here");
00518         return GE_FALSE;
00519 }

void DirTree_SetFileAttributes DirTree Tree,
geVFile_Attributes  Attributes
 

Definition at line 521 of file dirtree.c.

References DirTree::AttributeFlags, GE_VFILE_ATTRIB_DIRECTORY, and GE_VFILE_ATTRIB_READONLY.

Referenced by FSVFS_SetAttributes().

00522 {
00523         assert(Tree);
00524         assert(Attributes);
00525 
00526         // Only support the read only flag
00527         assert(!(Attributes & ~GE_VFILE_ATTRIB_READONLY));
00528         assert(!(Tree->AttributeFlags & GE_VFILE_ATTRIB_DIRECTORY));
00529 
00530         Tree->AttributeFlags = (Tree->AttributeFlags & ~GE_VFILE_ATTRIB_READONLY)  | Attributes;
00531 }

geBoolean DirTree_SetFileHints DirTree Tree,
const geVFile_Hints Hints
 

Definition at line 571 of file dirtree.c.

References GE_FALSE, GE_TRUE, geBoolean, geRam_Allocate, geRam_Free, geVFile_Hints::HintData, geVFile_Hints::HintDataLength, and DirTree::Hints.

Referenced by FSVFS_SetHints().

00572 {
00573         if      (Tree->Hints.HintData)
00574                 geRam_Free(Tree->Hints.HintData);
00575 
00576         if      (Hints->HintData)
00577         {
00578                 Tree->Hints.HintData = geRam_Allocate(Hints->HintDataLength);
00579                 if      (!Tree->Hints.HintData)
00580                         return GE_FALSE;
00581                 memcpy(Tree->Hints.HintData, Hints->HintData, Hints->HintDataLength);
00582         }
00583         Tree->Hints.HintDataLength = Hints->HintDataLength;
00584         return GE_TRUE;
00585 }

void DirTree_SetFileOffset DirTree Tree,
long  Offset
 

Definition at line 541 of file dirtree.c.

References DirTree::AttributeFlags, GE_VFILE_ATTRIB_DIRECTORY, and DirTree::Offset.

Referenced by FSVFS_Open().

00542 {
00543         assert(Leaf);
00544         assert(!(Leaf->AttributeFlags & GE_VFILE_ATTRIB_DIRECTORY));
00545 
00546         Leaf->Offset = Offset;
00547 }

void DirTree_SetFileSize DirTree Tree,
long  Size
 

Definition at line 194 of file dirtree.c.

References DirTree::Size.

Referenced by FSVFS_Close().

00195 {
00196         assert(Tree);
00197         Tree->Size = Size;
00198 }

void DirTree_SetFileTime DirTree Tree,
const geVFile_Time Time
 

Definition at line 557 of file dirtree.c.

References DirTree::Time.

Referenced by FSVFS_SetTime().

00558 {
00559         assert(Tree);
00560 
00561         Tree->Time = *Time;
00562 }

geBoolean DirTree_WriteToFile const DirTree Tree,
geVFile File
 

Definition at line 206 of file dirtree.c.

References DirTree_WriteToFile1(), GE_FALSE, GE_TRUE, and geBoolean.

Referenced by FSVFS_Close().

00207 {
00208         geBoolean       Res;
00209         long            Size;
00210 
00211         Res = DirTree_WriteToFile1(Tree, File, &Size);
00212         if      (Res == GE_FALSE)
00213                 return Res;
00214 
00215         return GE_TRUE;
00216 }


Generated on Tue Sep 30 12:37:25 2003 for GTestAndEngine by doxygen 1.3.2