mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-16 14:05:45 +01:00
write conf scripts
This commit is contained in:
35
src/io/conf.c
Normal file
35
src/io/conf.c
Normal 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
12
src/io/conf.h
Normal 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));
|
||||
Reference in New Issue
Block a user