SparrowFile is for file handling. Most basic tasks (opening, reading a amount of bytes, closing) are already done by SDL. sparrowFile extends this to checking whether a file exists, reading until specific signs, searching files, creating folders, etc. Use only /! not \ ... For more information about file functions see http://www.libsdl.org/cgi/docwiki.cgi/SDL_API and scroll down to “Files (RWops)”. Keep in mind: spFilePointer and SDL_RWops* are EXACTLY the same. ;-)
sparrowFile | SparrowFile is for file handling. |
Enumerations | |
spFileError | Enumeration for errors while working with files |
spFileType | Enumeration for file types |
spFileSortType | This enumeration is needed for sorting files when searching in a folder |
Types | |
spFilePointer | Same lik SDL_RWops*, but looks better ;) |
spFileList | Linked list type for searching results, which contains found files. |
Functions | |
spFileExists | Tests, whether the file “filename” exists ;-) |
spReadOneLine | Reads one line from a SDL_RWops file. |
spReadUntil | Reads signs from the file “file” until the buffer is full (buffer_len) or the sign “end_sign” is reached. |
spCreateDirectoryChain | Creates a directory chain (like /home/user/.config/pinball/settings) if it not exists already. |
spRemoveFile | Removes/deletes a file |
spRemoveDirectory | Removes an EMPTY directory |
spRenameFile | Renames a file |
spRenameDirectory | Renames a directory, works exactly like spRenameFile. |
spFileGetDirectory | Searches for files Puts a double linked list of found files in directory to pointer, found files are directly extracted from the system and may very well not be ordered. |
spFileDeleteList | Deletes a list created by spFileGetDirectory. |
spFileSortList | Sorts the file list like you want. |
Enumeration for errors while working with files
Linked list type for searching results, which contains found files.
name (char*) | filename |
type (spFileType) | filetype, see spFileType |
prev (spFileList*) | previous found |
next (spFileList*) | next found |
count (int) | only valid for the first element, describes the number of found files |
PREFIX int spReadOneLine( spFilePointer file , char * buffer, int buffer_len )
Reads one line from a SDL_RWops file.
file | the file to read |
buffer | where the file content is written to |
buffer_len | the length of buffer (+ zero byte!). |
int | If the end of file is reached, 1 is returned, else 0 |
PREFIX int spReadUntil( spFilePointer file , char * buffer, int buffer_len, char end_sign, char ignore_windows_return )
Reads signs from the file “file” until the buffer is full (buffer_len) or the sign “end_sign” is reached. The sign before “end_sign” is the last sign of the string! If you read more signs from the file, the sign AFTER “end_sign” is the next you will read. It is useful for parsing simple XML files.
file | the file to be read |
buffer | the buffer for reading signs |
buffer_len | the length of the buffer |
end_sign | the sign to which it will be read |
ignore_windows_return | Windows uses 2 signs for line breaks (VERY smart...), so if you set ignore_windows_return to 1, \r will be ignored. Necessary for Windows text files, but for binary files it doesn’t make sense at all. |
int | Like spReadOneLine it returns 1 if eof is reached, else 0. |
PREFIX spFileError spCreateDirectoryChain( const char * directories )
Creates a directory chain (like /home/user/.config/pinball/settings) if it not exists already. That means if you create e.g. rainbow/dash, the folder rainbow will be created if it doesn’t exist.
directories | the path of the directory to create |
spFileError | SP_FILE_EVERYTHING_OK if no error, else see spFileError |
PREFIX spFileError spRemoveFile( const char * filename )
Removes/deletes a file
filename | the name of the file |
spFileError | SP_FILE_EVERYTHING_OK if no error, else see spFileError |
PREFIX spFileError spRemoveDirectory( const char * dirname )
Removes an EMPTY directory
dirname | the name of the directory |
spFileError | SP_FILE_EVERYTHING_OK if no error, else see spFileError |
PREFIX spFileError spRenameFile( const char* filename , const char * newname )
Renames a file
filename | the old filename |
newname | the new filename |
spFileError | SP_FILE_EVERYTHING_OK if no error, else see spFileError |
PREFIX spFileError spFileGetDirectory( spFileListPointer * pointer, char * directory, int recursive, int no_hidden_files )
Searches for files Puts a double linked list of found files in directory to pointer, found files are directly extracted from the system and may very well not be ordered. Call spFileSortList on the list afterwards. Finally call spFileDeleteList to dispose the list. Returned filepaths include the passed directory string
pointer | pointer to an existing <spFileListPointer> (not a struct), the result will be placed in here |
directory | path of the directory to be searched. Use forward slashes (even on Windows). Use “.” for working directory, “..” for parent dir. DON’T include a trailing slash |
recursive | if 0 only directory will be searched, if 1 the subdirectories, too. Be carefull with infinite directory loops! |
no_hidden_files | if 1, hidden files like .git are ignored. |
spFileError | SP_FILE_EVERYTHING_OK if no error, else see spFileError |
PREFIX void spFileSortList( spFileListPointer * list, spFileSortType sortBy )
Sorts the file list like you want.
list | the list to be sorted |
sortBy | the sorting pattern. The possible sort pattern are (self-explanatory): SP_FILE_SORT_BY_NAME, SP_FILE_SORT_BY_TYPE, SP_FILE_SORT_BY_TYPE_AND_NAME. Add SP_FILE_SORT_BACKWARDS to sort backwards |
Tests, whether the file “filename” exists ;-)
PREFIX int spFileExists( const char * filename )
Reads one line from a SDL_RWops file.
PREFIX int spReadOneLine( spFilePointer file , char * buffer, int buffer_len )
Reads signs from the file “file” until the buffer is full (buffer_len) or the sign “end_sign” is reached.
PREFIX int spReadUntil( spFilePointer file , char * buffer, int buffer_len, char end_sign, char ignore_windows_return )
Creates a directory chain (like /home/user/.config/pinball/settings) if it not exists already.
PREFIX spFileError spCreateDirectoryChain( const char * directories )
Removes/deletes a file
PREFIX spFileError spRemoveFile( const char * filename )
Removes an EMPTY directory
PREFIX spFileError spRemoveDirectory( const char * dirname )
Renames a file
PREFIX spFileError spRenameFile( const char* filename , const char * newname )
Searches for files Puts a double linked list of found files in directory to pointer, found files are directly extracted from the system and may very well not be ordered.
PREFIX spFileError spFileGetDirectory( spFileListPointer * pointer, char * directory, int recursive, int no_hidden_files )
Deletes a list created by spFileGetDirectory.
PREFIX void spFileDeleteList( spFileListPointer list )
Sorts the file list like you want.
PREFIX void spFileSortList( spFileListPointer * list, spFileSortType sortBy )