meta: rename to fx
This commit is contained in:
@@ -1,48 +1,48 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <blue/core/stringstream.h>
|
||||
#include <blue/io/path.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/io/path.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <Windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
struct b_path {
|
||||
struct b_dsref base;
|
||||
struct b_string *pathstr;
|
||||
struct fx_path {
|
||||
struct fx_dsref base;
|
||||
struct fx_string *pathstr;
|
||||
};
|
||||
|
||||
static void path_release(struct b_dsref *obj);
|
||||
static void path_to_string(struct b_dsref *obj, struct b_stringstream *out);
|
||||
static void path_release(struct fx_dsref *obj);
|
||||
static void path_to_string(struct fx_dsref *obj, struct fx_stringstream *out);
|
||||
|
||||
static struct b_dsref_type path_type = {
|
||||
static struct fx_dsref_type path_type = {
|
||||
.t_name = "corelib::path",
|
||||
.t_flags = B_DSREF_FUNDAMENTAL,
|
||||
.t_id = B_DSREF_TYPE_PATH,
|
||||
.t_instance_size = sizeof(struct b_path),
|
||||
.t_flags = FX_DSREF_FUNDAMENTAL,
|
||||
.t_id = FX_DSREF_TYPE_PATH,
|
||||
.t_instance_size = sizeof(struct fx_path),
|
||||
.t_release = path_release,
|
||||
.t_to_string = path_to_string,
|
||||
};
|
||||
|
||||
struct b_path *b_path_create()
|
||||
struct fx_path *fx_path_create()
|
||||
{
|
||||
struct b_path *path
|
||||
= (struct b_path *)b_dsref_type_instantiate(&path_type);
|
||||
struct fx_path *path
|
||||
= (struct fx_path *)fx_dsref_type_instantiate(&path_type);
|
||||
if (!path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
path->pathstr = b_string_create();
|
||||
path->pathstr = fx_string_create();
|
||||
if (!path->pathstr) {
|
||||
b_path_release(path);
|
||||
fx_path_release(path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
struct b_path *b_path_create_root()
|
||||
struct fx_path *fx_path_create_root()
|
||||
{
|
||||
const char *system_drive = getenv("SystemDrive");
|
||||
if (!system_drive) {
|
||||
@@ -52,20 +52,20 @@ struct b_path *b_path_create_root()
|
||||
|
||||
size_t system_drive_len = strlen(system_drive);
|
||||
|
||||
struct b_path *path = b_path_create();
|
||||
struct fx_path *path = fx_path_create();
|
||||
if (!path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_string_append_cstr(path->pathstr, system_drive);
|
||||
fx_string_append_cstr(path->pathstr, system_drive);
|
||||
if (system_drive[system_drive_len - 1] != '\\') {
|
||||
b_string_append_cstr(path->pathstr, "\\");
|
||||
fx_string_append_cstr(path->pathstr, "\\");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
struct b_path *b_path_create_cwd()
|
||||
struct fx_path *fx_path_create_cwd()
|
||||
{
|
||||
DWORD cwd_len = GetCurrentDirectory(0, NULL);
|
||||
if (cwd_len == 0) {
|
||||
@@ -83,7 +83,7 @@ struct b_path *b_path_create_cwd()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct b_path *path = b_path_create();
|
||||
struct fx_path *path = fx_path_create();
|
||||
if (!path) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -91,16 +91,16 @@ struct b_path *b_path_create_cwd()
|
||||
for (DWORD i = 0; i < cwd_len; i++) {
|
||||
TCHAR c = cwd_buf[i];
|
||||
char s[] = {(c >= 128 ? '?' : (char)c), 0};
|
||||
b_string_append_cstr(path->pathstr, s);
|
||||
fx_string_append_cstr(path->pathstr, s);
|
||||
}
|
||||
|
||||
free(cwd_buf);
|
||||
return path;
|
||||
}
|
||||
|
||||
struct b_path *b_path_create_from_cstr(const char *cstr)
|
||||
struct fx_path *fx_path_create_from_cstr(const char *cstr)
|
||||
{
|
||||
struct b_path *path = b_path_create();
|
||||
struct fx_path *path = fx_path_create();
|
||||
if (!path) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -119,38 +119,38 @@ struct b_path *b_path_create_from_cstr(const char *cstr)
|
||||
|
||||
|
||||
char s[] = {c, 0};
|
||||
b_string_append_cstr(path->pathstr, s);
|
||||
fx_string_append_cstr(path->pathstr, s);
|
||||
prev = c;
|
||||
}
|
||||
|
||||
while (b_string_back(path->pathstr) == '/') {
|
||||
b_string_pop_back(path->pathstr);
|
||||
while (fx_string_back(path->pathstr) == '/') {
|
||||
fx_string_pop_back(path->pathstr);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static void append_path(struct b_path *dest, const struct b_path *src)
|
||||
static void append_path(struct fx_path *dest, const struct fx_path *src)
|
||||
{
|
||||
if (b_path_is_absolute(src)) {
|
||||
b_string_clear(dest->pathstr);
|
||||
b_string_append_s(dest->pathstr, src->pathstr);
|
||||
if (fx_path_is_absolute(src)) {
|
||||
fx_string_clear(dest->pathstr);
|
||||
fx_string_append_s(dest->pathstr, src->pathstr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (b_string_back(dest->pathstr) != '/'
|
||||
&& b_string_front(src->pathstr) != '/') {
|
||||
if (fx_string_back(dest->pathstr) != '/'
|
||||
&& fx_string_front(src->pathstr) != '/') {
|
||||
char s[] = {'/', 0};
|
||||
b_string_append_cstr(dest->pathstr, s);
|
||||
fx_string_append_cstr(dest->pathstr, s);
|
||||
}
|
||||
|
||||
b_string_append_s(dest->pathstr, src->pathstr);
|
||||
fx_string_append_s(dest->pathstr, src->pathstr);
|
||||
}
|
||||
|
||||
struct b_path *b_path_join(
|
||||
const b_path *paths[], size_t nr_paths)
|
||||
struct fx_path *fx_path_join(
|
||||
const fx_path *paths[], size_t nr_paths)
|
||||
{
|
||||
struct b_path *result = b_path_create();
|
||||
struct fx_path *result = fx_path_create();
|
||||
if (!result) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -164,24 +164,24 @@ struct b_path *b_path_join(
|
||||
return result;
|
||||
}
|
||||
|
||||
struct b_path *b_path_make_absolute(const struct b_path *in)
|
||||
struct fx_path *fx_path_make_absolute(const struct fx_path *in)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct b_path *b_path_make_relative(const struct b_path *in)
|
||||
struct fx_path *fx_path_make_relative(const struct fx_path *in)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct b_path *b_path_make_canonical(const struct b_path *in)
|
||||
struct fx_path *fx_path_make_canonical(const struct fx_path *in)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool b_path_is_absolute(const struct b_path *path)
|
||||
bool fx_path_is_absolute(const struct fx_path *path)
|
||||
{
|
||||
const char *s = b_string_ptr(path->pathstr);
|
||||
const char *s = fx_string_ptr(path->pathstr);
|
||||
|
||||
size_t i;
|
||||
for (i = 0; s[i]; i++) {
|
||||
@@ -203,15 +203,15 @@ bool b_path_is_absolute(const struct b_path *path)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool b_path_exists(const struct b_path *path)
|
||||
bool fx_path_exists(const struct fx_path *path)
|
||||
{
|
||||
DWORD attrib = GetFileAttributesA(b_path_ptr(path));
|
||||
DWORD attrib = GetFileAttributesA(fx_path_ptr(path));
|
||||
return attrib != INVALID_FILE_ATTRIBUTES;
|
||||
}
|
||||
|
||||
bool b_path_is_file(const struct b_path *path)
|
||||
bool fx_path_is_file(const struct fx_path *path)
|
||||
{
|
||||
DWORD attrib = GetFileAttributesA(b_path_ptr(path));
|
||||
DWORD attrib = GetFileAttributesA(fx_path_ptr(path));
|
||||
if (attrib == INVALID_FILE_ATTRIBUTES) {
|
||||
return false;
|
||||
}
|
||||
@@ -219,9 +219,9 @@ bool b_path_is_file(const struct b_path *path)
|
||||
return (attrib & FILE_ATTRIBUTE_NORMAL) != 0;
|
||||
}
|
||||
|
||||
bool b_path_is_directory(const struct b_path *path)
|
||||
bool fx_path_is_directory(const struct fx_path *path)
|
||||
{
|
||||
DWORD attrib = GetFileAttributesA(b_path_ptr(path));
|
||||
DWORD attrib = GetFileAttributesA(fx_path_ptr(path));
|
||||
if (attrib == INVALID_FILE_ATTRIBUTES) {
|
||||
return false;
|
||||
}
|
||||
@@ -229,20 +229,20 @@ bool b_path_is_directory(const struct b_path *path)
|
||||
return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
}
|
||||
|
||||
const char *b_path_ptr(const struct b_path *path)
|
||||
const char *fx_path_ptr(const struct fx_path *path)
|
||||
{
|
||||
return b_string_ptr(path->pathstr);
|
||||
return fx_string_ptr(path->pathstr);
|
||||
}
|
||||
|
||||
void path_release(struct b_dsref* obj)
|
||||
void path_release(struct fx_dsref* obj)
|
||||
{
|
||||
struct b_path *path = B_PATH(obj);
|
||||
b_string_release(path->pathstr);
|
||||
struct fx_path *path = FX_PATH(obj);
|
||||
fx_string_release(path->pathstr);
|
||||
}
|
||||
|
||||
void path_to_string(struct b_dsref* obj, struct b_stringstream* out)
|
||||
void path_to_string(struct fx_dsref* obj, struct fx_stringstream* out)
|
||||
{
|
||||
struct b_path *path = (struct b_path *)obj;
|
||||
struct fx_path *path = (struct fx_path *)obj;
|
||||
|
||||
b_stringstream_add(out, b_string_ptr(path->pathstr));
|
||||
fx_stringstream_add(out, fx_string_ptr(path->pathstr));
|
||||
}
|
||||
Reference in New Issue
Block a user