LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_path.c File Reference

Functions

LG_Path lg_path (const char *s, lg_path_type t)
 
const char * lg_path_resolve (const LG_Path *path)
 
LG_Path lg_path_in_assets_from_fullpath_string (const char *full_path)
 
LG_Path lg_path_in_wrdir_from_fullpath_string (const char *full_path)
 
LG_Path lg_path_from_fullpath_string (const char *full_path)
 
lg_path_type lg_path_get_type_from_fullpath_string (const char *full_path)
 
zboolean lg_path_string_resolve (char *path)
 
const char * lg_path_type_get_string (lg_path_type type)
 
zboolean lg_path_are_equal (const LG_Path *path1, const LG_Path *path2)
 
void lg_path_info (LG_Path *path)
 
void lg_resolved_path0_free_buffer ()
 

Detailed Description

=== LG_Path stuff ===

Function Documentation

◆ lg_path()

LG_Path lg_path ( const char *  s,
lg_path_type  t 
)

Create a new LG_Path, ie a path and an associated type, which specify if this path is relative inside the ASSETS folder, or relative inside the APP_WRITABLE folder, or full, or a filename only, or unknown

LG_Path are LOSSLESS, CROSS-APP, AND CROSS-PLATFORM, so you should use them everywhere they are relevant

String max len = LG_PATH_MAX_LEN (see below)

In lg_goodies.h:

#define LG_PATH_MAX_LEN (512 - 1 - 1) // 2nd -1 to keep LG_Path size at 512
typedef int8_t lg_path_type;
enum {IN_ASSETS, IN_APP_WR_DIR, FULL, NAME_ONLY, UNSPECIFIED};
// sizeof(LG_Path) = 512 bytes
typedef struct __attribute__((packed, aligned(4))) {
char s[LG_PATH_MAX_LEN + 1];
lg_path_type t;
Definition lg_path.h:17

Usage example:

LG_Path path = lg_path("hello1/hello2", IN_ASSETS)
LG_Path lg_path(const char *s, lg_path_type t)
Definition lg_path.c:46
Parameters
sString containing the path - if NULL, path is set to an empty string
tPath type, one of IN_ASSETS, IN_APP_WR_DIR, FULL, NAME_ONLY, UNSPECIFIED - if invalid, set to UNSPECIFIED
Returns
A new LG_Path

◆ lg_path_resolve()

const char * lg_path_resolve ( const LG_Path *  path)

Resolve LG_PATH, ie get the full path - at runtime

Parameters
pathA LG_Path
Returns
The full path if OK, empty string on error

◆ lg_path_in_assets_from_fullpath_string()

LG_Path lg_path_in_assets_from_fullpath_string ( const char *  full_path)

Return a valid LG_Path with type IN_ASSETS from a valid full path string in ASSETS

Parameters
full_pathString to full path
Returns
LG_Path with type IN_ASSETS, or full path - FULL if not in ASSETS, or empty string - UNSPECIFIED on error

◆ lg_path_in_wrdir_from_fullpath_string()

LG_Path lg_path_in_wrdir_from_fullpath_string ( const char *  full_path)

Return a valid LG_Path with type IN_APP_WR_DIR from a valid full path string in app wr dir

Parameters
full_pathString to full path
Returns
LG_Path with type IN_APP_WR_DIR, or full path - FULL if not in APP WR DIR, or empty string - UNSPECIFIED on error

◆ lg_path_from_fullpath_string()

LG_Path lg_path_from_fullpath_string ( const char *  full_path)

Return a valid LG_Path from a valid full path string

Path type set to IN_ASSETS, IN_APP_WR_DIR, FULL, or UNSPECIFIED

Parameters
full_pathString to full path
Returns
LG_Path, empty string LG_Path with type UNSPECIFIED on error

◆ lg_path_get_type_from_fullpath_string()

lg_path_type lg_path_get_type_from_fullpath_string ( const char *  full_path)

Return whether a valid full path string points to the ASSETS dir, or the app wr dir, or somewhere else

Parameters
full_pathString to full path
Returns
type A lg_path_type value if it can be determined (ie, IN_ASSETS or IN_APP_WR_DIR), UNSPECIFIED otherwise

◆ lg_path_string_resolve()

zboolean lg_path_string_resolve ( char *  path)

Resolve a path string (not a path) which includes "../", "./" sequences and extra '/' , making it a valid one

-> doesn't return a full path, unless string is a full path

Change path in place

This func is called internally by lg_path_resolve() but you may use it with any 'writable' string

Parameters
pathPath to resolve - will be overwritten
Returns
TRUE if OK, FALSE on error (no changes applied)

◆ lg_path_type_get_string()

const char * lg_path_type_get_string ( lg_path_type  type)

Get string from lg_path_type

IN_ASSETS, IN_APP_WR_DIR, FULL, NAME_ONLY, UNSPECIFIED -> 'IN_ASSETS', 'IN_APP_WR_DIR', 'FULL', 'NAME_ONLY', 'UNSPECIFIED'

Parameters
typelg_path_type value
Returns
String from lg_path_type

◆ lg_path_are_equal()

zboolean lg_path_are_equal ( const LG_Path *  path1,
const LG_Path *  path2 
)

Compare two LG_PATH

Parameters
path1A LG_Path
path2Another LG_Path
Returns
TRUE if paths are equal, FALSE otherwise

◆ lg_path_info()

void lg_path_info ( LG_Path *  path)

Print out LG_Path info, ie string and type

Parameters
pathPointer to a LG_Path

◆ lg_resolved_path0_free_buffer()

void lg_resolved_path0_free_buffer ( )

Free resolved_path0 buffer - called by lg_quit(), you should never call this fuction directly