Compare commits

...

3 Commits

Author SHA1 Message Date
9e8f5958c7 write conf scripts 2025-12-15 18:52:47 +01:00
bc0743a72b add __assume__ macro definition in atrb.h 2025-12-15 12:32:34 +01:00
81b21ff7ce move windowing code into io/win 2025-12-15 10:02:54 +01:00
12 changed files with 57 additions and 6 deletions

35
src/io/conf.c Normal file
View File

@@ -0,0 +1,35 @@
#include "conf.h"
#include <string.h>
#include "../types.h"
#include "../util/atrb.h"
/* Matches s1 with s2, returns a pointer to s1 where the match stopped. */
static const char *strmat(const char *s1, const char *s2) PURE NONNULL((1, 2));
static const char *strmat(const char *s1, const char *s2)
{
while ((*s1 == *s2) & !!*s1)
s1++, s2++;
return s1;
}
int conf_getkeyval(const char *restrict buf, const char *const restrict *restrict keys, int klen, const char *restrict *restrict out)
{
const char *tmp = NULL;
ASSUME((klen > 0));
int i = 0;
for (; i < klen && !tmp; i++) {
tmp = strmat(buf, keys[i]);
tmp = keys[i][buf - tmp] ? tmp : 0;
}
if (!tmp || *tmp != '=')
return -1;
*out = tmp + 1;
return i;
}
int conf_val(int);

12
src/io/conf.h Normal file
View File

@@ -0,0 +1,12 @@
#pragma once
#include "../types.h"
#include "../util/atrb.h"
/* Gets the key and value, if present. Writes the pointer for the value to `out`.
* Returns the key index, or <0 upon failure. */
int conf_getkeyval(const char *restrict buf, const char *const restrict *restrict keys, int klen,
const char *restrict *restrict out) NONNULL((1, 2, 4));
/* Processes the value of `type` in `val`. Outputs to `out`.
* Returns non-zero on failure. */
int conf_procval(u8 type, const char *restrict val, void *restrict out) NONNULL((2, 3));

View File

@@ -7,8 +7,8 @@
#include <glad/gl.h>
#include <stdint.h>
#include "../types.h"
#include "../util/error.h"
#include "../../types.h"
#include "../../util/error.h"
#include "shader.h"
#define VERTC 3

View File

@@ -7,7 +7,7 @@
#include <stdint.h>
#include <stdio.h>
#include "../util/error.h"
#include "../../util/error.h"
// NOTE: we are currently just sucking up the memory costs for ease. We can either include the source files themselves. Or use compression, where I'd prefer the latter for ease of installation.

View File

@@ -7,8 +7,8 @@
#include <assert.h>
#include <glad/gl.h>
#include "../types.h"
#include "../util/error.h"
#include "../../types.h"
#include "../../util/error.h"
#include "input.h"
#include "render.h"

View File

@@ -6,7 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "io/window.h"
#include "io/win/window.h"
#include "util/error.h"
/* reroutes GLFW errors to our logging system. */

View File

@@ -57,4 +57,8 @@
#else
#define NONNULL(args)
#endif
#if __has_attribute(__assume__)
#define ASSUME(args) __attribute__((__assume__ args))
#endif
#endif