Начало

This commit is contained in:
cfif 2025-09-23 17:12:43 +03:00
commit 91848cb641
6 changed files with 196 additions and 0 deletions

11
Inc/BaseTypes.h Normal file
View File

@ -0,0 +1,11 @@
//
// Created by cfif on 13.10.22.
//
#ifndef BASETYPES_H
#define BASETYPES_H
#include "BaseTypes/String.h"
#include "BaseTypes/Strings.h"
#endif //BASETYPES_H

24
Inc/BaseTypes/String.h Normal file
View File

@ -0,0 +1,24 @@
//
// Created by xemon on 10.11.22.
//
#ifndef UVEOS_ON_NATION_STRING_H
#define UVEOS_ON_NATION_STRING_H
#include "stdint.h"
typedef struct {
uint8_t length;
uint8_t max_length;
uint8_t readonly;
char str[32];
} tString;
uint8_t getStrLen(char *str);
void vInitStringOnlyLength(tString *tstr, uint8_t length);
void vInitString(tString *tstr, void *str, uint8_t length, uint8_t max_length, uint8_t readonly);
#endif //UVEOS_ON_NATION_STRING_H

81
Inc/BaseTypes/Strings.h Normal file
View File

@ -0,0 +1,81 @@
//
// Created by xemon on 10.11.22.
//
#ifndef UVEOS_ON_NATION_STRINGS_H
#define UVEOS_ON_NATION_STRINGS_H
#include "stdint.h"
#define tString(T) \
typedef struct { \
uint8_t length; \
char data[T]; \
} tString##T;
tString(8)
tString(16)
tString(32)
tString(64)
tString(128)
tString(255)
typedef struct {
uint8_t length;
char *data;
} tStringStatic;
typedef struct {
uint8_t *length;
char *data;
} tStringLink;
#define StringGetLinkTemplateD(T) \
tStringLink String##T##GetLink(tString##T *string);
StringGetLinkTemplateD(8)
StringGetLinkTemplateD(16)
StringGetLinkTemplateD(32)
StringGetLinkTemplateD(64)
StringGetLinkTemplateD(128)
StringGetLinkTemplateD(255)
StringGetLinkTemplateD(Static)
#define StringStaticInit(STR) (tStringStatic){.data = (char*)(STR), .length = sizeof(STR)-1}
#define StringArrInit(STR) (tStringStatic){.data = (char*)(STR), .length = sizeof(STR)}
#define StringCopyTD(T) \
void String##T##Copy(tString##T *dest, char *source, uint8_t sourceLen);
StringCopyTD(8)
StringCopyTD(16)
StringCopyTD(32)
StringCopyTD(64)
StringCopyTD(128)
StringCopyTD(255)
#define StringCopyStaticTemplate(T) \
String##T##Copy(DEST,STR,sizeof(STR)-1)
#define String8CopyStatic(DEST, STR) String8Copy(DEST,STR,sizeof(STR)-1)
#define String16CopyStatic(DEST, STR) String16Copy(DEST,STR,sizeof(STR)-1)
#define String32CopyStatic(DEST, STR) String32Copy(DEST,STR,sizeof(STR)-1)
#define String64CopyStatic(DEST, STR) String64Copy(DEST,STR,sizeof(STR)-1)
#define String128CopyStatic(DEST, STR) String128Copy(DEST,STR,sizeof(STR)-1)
#define String255CopyStatic(DEST, STR) String128Copy(DEST,STR,sizeof(STR)-1)
#endif //UVEOS_ON_NATION_STRINGS_H

27
Src/BaseTypes.c Normal file
View File

@ -0,0 +1,27 @@
//
// Created by cfif on 13.10.22.
//
#include <string.h>
#include "BaseTypes.h"
uint8_t getStrLen(char *str) {
uint8_t len = 0;
while (str[len]) {
++len;
}
return len;
}
void vInitString(tString *tstr, void *str, uint8_t length, uint8_t max_length, uint8_t readonly) {
tstr->length = length;
tstr->max_length = max_length;
tstr->readonly = readonly;
memcpy(tstr->str, str, length);
}
void vInitStringOnlyLength(tString *tstr, uint8_t length) {
tstr->length = length;
}

43
Src/Strings.c Normal file
View File

@ -0,0 +1,43 @@
//
// Created by xemon on 11.11.22.
//
#include "BaseTypes/Strings.h"
#include "memory.h"
#define StringGetLinkTemplate(T) \
tStringLink String##T##GetLink(tString##T *string) { \
return (tStringLink) {.length = &string->length, .data = string->data}; \
}
StringGetLinkTemplate(8)
StringGetLinkTemplate(16)
StringGetLinkTemplate(32)
StringGetLinkTemplate(64)
StringGetLinkTemplate(128)
StringGetLinkTemplate(Static)
#define StringStaticInit(STR) (tStringStatic){.data = STR, .length = sizeof(STR)-1}
#define StringCopyT(T) \
void String##T##Copy(tString##T *dest, char *source, uint8_t sourceLen) { \
dest->length = sourceLen > T ? T : sourceLen; \
memcpy(dest->data, source, dest->length); \
}
StringCopyT(8)
StringCopyT(16)
StringCopyT(32)
StringCopyT(64)
StringCopyT(128)

10
modular.json Normal file
View File

@ -0,0 +1,10 @@
{
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}