Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
fileUtils.c File Reference

Macros

#define iniPrintf(fmt, ...)
 
#define iniPuts(str)
 
#define STATE_PRE_KEY   0
 
#define STATE_COMMENT   1
 
#define STATE_KEY   2
 
#define STATE_POST_KEY   3
 
#define STATE_PRE_VAL   4
 
#define STATE_VAL   5
 
#define STATE_SECTION   6
 

Functions

long getFileSize (const char *fname)
 Return the total size of the given file by opening it and seeking to the end.
 
bool doesFileExist (const char *fname)
 Returns true if the file at the given path exists.
 
const char * get_filename (const char *filename)
 Get the filename part of a file path, after the last '/'.
 
bool isSourceFileNewer (const char *sourceFile, const char *destFile)
 Returns true if the file sourceFile has a last-modified time after that of destFile, or if destFile does not exist.
 
bool deleteFile (const char *path)
 Delete the file at the given path in a cross-platform way.
 
bool getOptionsFromIniFile (processorOptions_t *options, const char *file)
 Parse the file with the given name as an INI file and write its data to options.
 
const char * getFullOptionKey (char *buf, size_t n, const optPair_t *option)
 Writes the <section>.<key> value to the given buffer and returns the key.
 
void deleteOptions (processorOptions_t *options)
 Deallocates memory for a processorOptions_t.
 
const char * getStrOption (const processorOptions_t *options, const char *name)
 Retrieve an option by name and return its value as a string, or NULL if the key is not found.
 
int getIntOption (const processorOptions_t *options, const char *name, int defaultVal)
 Retrieve an option by name from the given options list and parse it as an integer, using a default value if it cannot be found or is not an integer.
 
bool getBoolOption (const processorOptions_t *options, const char *name, bool defaultVal)
 Retrieve an option by name from the given options list and parse it as a boolean, using a default value if it cannot be found or is not a boolean.
 
bool hasOption (const processorOptions_t *options, const char *name)
 Searches the given options list for a key with the given name.
 

Macro Definition Documentation

◆ iniPrintf

#define iniPrintf ( fmt,
... )

◆ iniPuts

#define iniPuts ( str)

◆ STATE_PRE_KEY

#define STATE_PRE_KEY   0

◆ STATE_COMMENT

#define STATE_COMMENT   1

◆ STATE_KEY

#define STATE_KEY   2

◆ STATE_POST_KEY

#define STATE_POST_KEY   3

◆ STATE_PRE_VAL

#define STATE_PRE_VAL   4

◆ STATE_VAL

#define STATE_VAL   5

◆ STATE_SECTION

#define STATE_SECTION   6

Function Documentation

◆ getFileSize()

long getFileSize ( const char * fname)

Return the total size of the given file by opening it and seeking to the end.

Parameters
fnameThe path to the file to measure
Returns
long The total size of the file in bytes

◆ doesFileExist()

bool doesFileExist ( const char * fname)

Returns true if the file at the given path exists.

Parameters
fnameThe path to the file to check
Returns
true if the file exists
false if the file does not exist or otherwise cannot be read

◆ get_filename()

const char * get_filename ( const char * filename)

Get the filename part of a file path, after the last '/'.

Parameters
filenameThe path to return the filename of
Returns
const char* A pointer to the filename within filename

◆ isSourceFileNewer()

bool isSourceFileNewer ( const char * sourceFile,
const char * destFile )

Returns true if the file sourceFile has a last-modified time after that of destFile, or if destFile does not exist.

Parameters
sourceFileThe path to the "source" file, from which destFile is generated
destFileThe path to the "destination" file path, which should be regenerated if older than sourceFile.
Returns
true sourceFile was modified after destFile, so destFile should be updated
false destFile was modified after sourceFile, so destFile does not need to be updated

◆ deleteFile()

bool deleteFile ( const char * path)

Delete the file at the given path in a cross-platform way.

Parameters
pathThe file to delete
Returns
true if the file was successfully deleted
false if there was an error deleting the file

◆ getOptionsFromIniFile()

bool getOptionsFromIniFile ( processorOptions_t * options,
const char * file )

Parse the file with the given name as an INI file and write its data to options.

Parameters
optionsAn uninitialized options array to write INI file data to
fileThe path to the INI file to read
Returns
true If the INI file was successfully parsed
false If there was an error parsing the INI file or it could not be read

◆ getFullOptionKey()

const char * getFullOptionKey ( char * buf,
size_t n,
const optPair_t * option )

Writes the <section>.<key> value to the given buffer and returns the key.

If the given option has no section, the original key may be returned without using the buffer.

Parameters
bufThe buffer to write the key to if necessary
nThe maximum number of characters to write to buf
optionThe option to write the key name of
Returns
char* A pointer to buf or option->name

◆ deleteOptions()

void deleteOptions ( processorOptions_t * options)

Deallocates memory for a processorOptions_t.

Parameters
optionsA pointer to the processorOptions_t to delete memory for

◆ getStrOption()

const char * getStrOption ( const processorOptions_t * options,
const char * name )

Retrieve an option by name and return its value as a string, or NULL if the key is not found.

Parameters
optionsThe options list to search
nameThe key name to search for
Returns
const char* The value of the found key, or NULL

◆ getIntOption()

int getIntOption ( const processorOptions_t * options,
const char * name,
int defaultVal )

Retrieve an option by name from the given options list and parse it as an integer, using a default value if it cannot be found or is not an integer.

Parameters
optionsThe options list to search
nameThe key name to search for
defaultValA value to return if the key cannot be found or the value is not an integer
Returns
int The parsed value, or the default value

◆ getBoolOption()

bool getBoolOption ( const processorOptions_t * options,
const char * name,
bool defaultVal )

Retrieve an option by name from the given options list and parse it as a boolean, using a default value if it cannot be found or is not a boolean.

The following values are considered as true: yes, true, 1, y, t, on And the following values are considered as false: no, false, 0, n, f, off Matching is case-insensitive. If the option value matches none of these strings, the default value will be returned instead.

Parameters
optionsThe options list to search
nameThe name of the key to search
defaultValA value to return if the value is not found or not a boolean
Returns
true
false

◆ hasOption()

bool hasOption ( const processorOptions_t * options,
const char * name )

Searches the given options list for a key with the given name.

Parameters
optionsThe options list to search
nameThe key name to search for
Returns
true if the key was contained in the options list
false if the key was not found