Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

84
glob/.clang-format Normal file
View File

@ -0,0 +1,84 @@
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 160
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: false
DerivePointerAlignment: false
DisableFormat: false
FixNamespaceComments: false
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp03
TabWidth: 4
UseCRLF: false
UseTab: ForIndentation
---
Language: Cpp
---
Language: ObjC

5
glob/.gitattributes vendored Normal file
View File

@ -0,0 +1,5 @@
* -text
# Yes github, it's really C
*.h linguist-language=c
*.c.h linguist-language=c
Backends/System/Windows/Libraries/** linguist-vendored

9
glob/kfile.js Normal file
View File

@ -0,0 +1,9 @@
let project = new Project('glob');
project.kore = false;
project.setCmd();
project.addFile('src/**');
resolve(project);

87
glob/src/dir.c Normal file
View File

@ -0,0 +1,87 @@
#include "dir.h"
#include "log.h"
#include <stddef.h>
#include <stdio.h>
#ifdef _WIN32
#include <Windows.h>
directory open_dir(const char *dirname) {
char pattern[1024];
strcpy(pattern, dirname);
strcat(pattern, "\\*");
WIN32_FIND_DATAA data;
directory dir;
dir.handle = FindFirstFileA(pattern, &data);
if (dir.handle == INVALID_HANDLE_VALUE) {
kmake_log(LOG_LEVEL_ERROR, "FindFirstFile failed (%d)\n", GetLastError());
exit(1);
}
FindNextFileA(dir.handle, &data);
return dir;
}
file read_next_file(directory *dir) {
WIN32_FIND_DATAA data;
file file;
file.valid = FindNextFileA(dir->handle, &data) != 0;
if (file.valid) {
strcpy(file.name, data.cFileName);
}
else {
file.name[0] = 0;
}
return file;
}
void close_dir(directory *dir) {
FindClose(dir->handle);
}
static char current_working_dir[MAX_PATH];
const char *working_dir(void) {
wchar_t path[MAX_PATH];
DWORD length = GetCurrentDirectoryW(MAX_PATH, path);
WideCharToMultiByte(CP_ACP, 0, path, length, current_working_dir, MAX_PATH, NULL, NULL);
return current_working_dir;
}
#else
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
directory open_dir(const char *dirname) {
directory dir;
dir.handle = opendir(dirname);
return dir;
}
file read_next_file(directory *dir) {
struct dirent *entry = readdir(dir->handle);
while (entry != NULL && (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)) {
entry = readdir(dir->handle);
}
file f;
f.valid = entry != NULL;
if (f.valid) {
strcpy(f.name, entry->d_name);
}
return f;
}
void close_dir(directory *dir) {}
#endif

26
glob/src/dir.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct directory {
void *handle;
} directory;
typedef struct file {
bool valid;
char name[256];
} file;
directory open_dir(const char *dirname);
file read_next_file(directory *dir);
void close_dir(directory *dir);
const char *working_dir(void);
#ifdef __cplusplus
}
#endif

59
glob/src/glob.cpp Normal file
View File

@ -0,0 +1,59 @@
#include "dir.h"
#include "log.h"
#include <string>
#include <vector>
const char *pattern = "../../kmake/**";
using std::string;
using std::vector;
string find_base_dir(const string &pattern) {
size_t last_break = pattern.size();
for (size_t i = 0; i < pattern.size(); ++i) {
if (pattern[i] == '/' || pattern[i] == '\\') {
last_break = i;
}
else if (pattern[i] == '*') {
return pattern.substr(0, last_break);
}
}
return pattern;
}
string to_absolute(const string &path) {
return string(working_dir()) + "/" + path;
}
vector<string> split(const string &path) {
vector<string> parts;
size_t last = 0;
for (size_t i = 0; i < path.size(); ++i) {
if (path[i] == '/' || path[i] == '\\') {
parts.push_back(path.substr(last, i - last));
last = i + 1;
}
}
parts.push_back(path.substr(last));
return parts;
}
int main(int argc, char **argv) {
string absolute = to_absolute(pattern);
string base = find_base_dir(pattern);
directory dir = open_dir(base.c_str());
file f = read_next_file(&dir);
while (f.valid) {
kmake_log(LOG_LEVEL_INFO, "Visited %s", f.name);
f = read_next_file(&dir);
}
auto parts = split(pattern);
for (auto &part : parts) {
kmake_log(LOG_LEVEL_INFO, "Part: %s", part.c_str());
}
return 0;
}

51
glob/src/log.c Normal file
View File

@ -0,0 +1,51 @@
#include "log.h"
#include <stdio.h>
#include <string.h>
#ifdef WIN32
#include <Windows.h>
#endif
#ifdef __android__
#include <android/log.h>
#endif
void kmake_log(log_level_t level, const char *format, ...) {
va_list args;
va_start(args, format);
kmake_log_args(level, format, args);
va_end(args);
}
void kmake_log_args(log_level_t level, const char *format, va_list args) {
#ifdef WIN32
{
char buffer[4096];
vsnprintf(buffer, 4090, format, args);
strcat(buffer, "\r\n");
OutputDebugStringA(buffer);
}
#endif
{
char buffer[4096];
vsnprintf(buffer, 4090, format, args);
strcat(buffer, "\n");
fprintf(level == LOG_LEVEL_INFO ? stdout : stderr, "%s", buffer);
}
#ifdef __android__
switch (level) {
case KINC_LOG_LEVEL_INFO:
__android_log_vprint(ANDROID_LOG_INFO, "krom", format, args);
break;
case KINC_LOG_LEVEL_WARNING:
__android_log_vprint(ANDROID_LOG_WARN, "krom", format, args);
break;
case KINC_LOG_LEVEL_ERROR:
__android_log_vprint(ANDROID_LOG_ERROR, "krom", format, args);
break;
}
#endif
}

17
glob/src/log.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum { LOG_LEVEL_INFO, LOG_LEVEL_WARNING, LOG_LEVEL_ERROR } log_level_t;
void kmake_log(log_level_t log_level, const char *format, ...);
void kmake_log_args(log_level_t log_level, const char *format, va_list args);
#ifdef __cplusplus
}
#endif