Compare commits
4 Commits
f3ae1aef64
...
f8f08c7473
Author | SHA1 | Date | |
---|---|---|---|
f8f08c7473 | |||
ca55dc2549 | |||
ce4be85d14 | |||
3ec25758ef |
8
.gitmodules
vendored
Normal file
8
.gitmodules
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
[submodule "intern/c-cpp-aliases"]
|
||||
path = intern/c-cpp-aliases
|
||||
url = https://git.thewizardapprentice.com/abdelrahman/c-cpp-aliases.git
|
||||
branch = main
|
||||
[submodule "intern/cpath"]
|
||||
path = intern/cpath
|
||||
url = https://git.thewizardapprentice.com/abdelrahman/cpath.git
|
||||
branch = main
|
10
compile
10
compile
@ -22,10 +22,10 @@ FG_BR_WHITE="\033[97"
|
||||
|
||||
CC=clang
|
||||
AR=ar
|
||||
CFLAGS="-Wall -Werror -pedantic -Iinclude "
|
||||
CFLAGS="-Wall -Werror -pedantic -Iinclude -Iintern/c-cpp-aliases -Iintern/cpath/include "
|
||||
|
||||
PCKR_SRC="\
|
||||
src/path_utils.c \
|
||||
intern/cpath/src/cpath.c \
|
||||
src/argparse.c \
|
||||
src/io.c \
|
||||
src/darr.c \
|
||||
@ -34,20 +34,20 @@ PCKR_SRC="\
|
||||
src/main.c"
|
||||
|
||||
PAKRD_SRC="\
|
||||
src/path_utils.c \
|
||||
intern/cpath/src/cpath.c \
|
||||
src/io.c \
|
||||
src/darr.c \
|
||||
src/pak.c"
|
||||
PAKRD_FLAGS="-c -fPIC"
|
||||
|
||||
PCKR_TEST_SRC="\
|
||||
src/path_utils.c \
|
||||
intern/cpath/src/cpath.c \
|
||||
src/io.c \
|
||||
src/pckr_test.c"
|
||||
PCKR_TEST_OUT="pckr_test"
|
||||
|
||||
PAKRD_TEST_SRC="\
|
||||
src/path_utils.c \
|
||||
intern/cpath/src/cpath.c \
|
||||
src/io.c \
|
||||
src/darr.c \
|
||||
src/pak.c \
|
||||
|
@ -1,27 +0,0 @@
|
||||
#ifndef ALIASES_H
|
||||
#define ALIASES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define u8 uint8_t
|
||||
#define u16 uint16_t
|
||||
#define u32 uint32_t
|
||||
#define u64 uint64_t
|
||||
|
||||
#define i8 int8_t
|
||||
#define i16 int16_t
|
||||
#define i32 int32_t
|
||||
#define i64 int64_t
|
||||
|
||||
#define f32 float
|
||||
#define f64 double
|
||||
#define f128 long double
|
||||
|
||||
#define INTERNAL static
|
||||
#define PERSISTENT static
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define CLASS_MEMBER static
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // !ALIASES_H
|
@ -1,18 +0,0 @@
|
||||
#ifndef PATH_UTILS_H
|
||||
#define PATH_UTILS_H
|
||||
|
||||
#include "aliases.h"
|
||||
|
||||
#define NUMPARTS(...) \
|
||||
(sizeof((const char *[]){"", __VA_ARGS__}) / sizeof(const char *) - 1)
|
||||
|
||||
#define JOIN_PATH(DST, ...) join_path(DST, NUMPARTS(__VA_ARGS__), __VA_ARGS__)
|
||||
|
||||
void join_path(char *dst, u64 count, ...);
|
||||
|
||||
#define DIRNAME(DST, PATH) dirup(DST, 1, PATH)
|
||||
#define DIRUP(DST, COUNT, PATH) dirup(DST, COUNT, PATH)
|
||||
|
||||
void dirup(char *dst, u64 levels, const char *path);
|
||||
|
||||
#endif // !PATH_UTILS_H
|
1
intern/c-cpp-aliases
Submodule
1
intern/c-cpp-aliases
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit f95f3aa499910286876c1f2cdceea8146ebcf7b1
|
1
intern/cpath
Submodule
1
intern/cpath
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 833ee11a4e1ab85e79f8a116d54ecb4432e87b01
|
2
src/io.c
2
src/io.c
@ -1,6 +1,6 @@
|
||||
#include "io.h"
|
||||
#include "aliases.h"
|
||||
#include "path_utils.h"
|
||||
#include "cpath.h"
|
||||
#include <dirent.h>
|
||||
#include <linux/limits.h>
|
||||
#include <stdio.h>
|
||||
|
@ -1,76 +0,0 @@
|
||||
#include "path_utils.h"
|
||||
#include "aliases.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__unix__) || defined(__APPLE__) || defined(__ANDROID__)
|
||||
INTERNAL char path_sep = '/';
|
||||
#elif defined(_WIN32) || defined(_WIN64)
|
||||
INTERNAL char path_sep = '\';
|
||||
#endif
|
||||
|
||||
void join_root_and_leaf(const char *root, const char *leaf, char *dst);
|
||||
|
||||
void join_path(char *dst, u64 count, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, count);
|
||||
|
||||
for (u64 i = 0; i < count; ++i) {
|
||||
join_root_and_leaf(dst, va_arg(args, const char *), dst);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void dirup(char *dst, u64 levels, const char *path) {
|
||||
if (levels < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
u64 end_index = 0;
|
||||
u64 sep_count = 0;
|
||||
|
||||
u64 length = strlen(path);
|
||||
if (path[length - 1] == path_sep) {
|
||||
--length;
|
||||
}
|
||||
|
||||
for (u64 i = length - 1; i >= 0; --i) {
|
||||
if (path[i] == path_sep) {
|
||||
++sep_count;
|
||||
end_index = i;
|
||||
|
||||
if (sep_count == levels) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sep_count < levels) {
|
||||
end_index = 0;
|
||||
}
|
||||
|
||||
strncpy(dst, path, end_index);
|
||||
}
|
||||
|
||||
void join_root_and_leaf(const char *root, const char *leaf, char *dst) {
|
||||
u64 root_length = strlen(root);
|
||||
u64 root_end = root_length - 1;
|
||||
|
||||
u64 leaf_length = strlen(leaf);
|
||||
u64 leaf_start = 0;
|
||||
|
||||
if (root[root_end] == path_sep) {
|
||||
--root_end;
|
||||
}
|
||||
|
||||
if (leaf[leaf_start] == path_sep) {
|
||||
++leaf_start;
|
||||
}
|
||||
|
||||
strncpy(dst, root, ++root_end);
|
||||
dst[root_end] = path_sep;
|
||||
strncpy(&(dst[++root_end]), &(leaf[leaf_start]), leaf_length - leaf_start);
|
||||
}
|
Loading…
Reference in New Issue
Block a user