Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"configurations": [
{
"name": "Star6E",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"__SIGMASTAR__",
"__INFINITY6__"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
},
{
"name": "Star6C",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"__SIGMASTAR__",
"__INFINITY6__",
"__INFINITY6C__"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
},
{
"name": "native(x86)",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_x86"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
},
{
"name": "sigmastar-infinity6c",
"compilerPath": "/home/home/src/msposd/toolchain/sigmastar-infinity6c/bin/arm-linux-gcc",
"intelliSenseMode": "linux-gcc-arm",
"cStandard": "c11",
"includePath": [
"/home/home/src/msposd",
"/home/home/src/msposd/sdk/infinity6/include",
"/home/home/src/msposd/toolchain/sigmastar-infinity6c/usr/include"
],
"defines": [
"__SIGMASTAR__",
"__INFINITY6__",
"__INFINITY6C__"
],
"compilerArgs": [
"-Wno-address-of-packed-member"
]
}
],
"version": 4
}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "UDP_OSD",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/msposd",
"program": "${workspaceFolder}/msposd",
"args": [
"--master",
"127.0.0.1:14550",
Expand Down
146 changes: 80 additions & 66 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,72 +1,86 @@
{
"workbench.colorTheme": "Default High Contrast",
"workbench.colorTheme": "Visual Studio Dark - C++",

"editor.formatOnSave": false,
"editor.formatOnType": false,
"editor.formatOnPaste": false,

"C_Cpp.clang_format_path": "/usr/bin/clang-format",
"C_Cpp.clang_format_style": "file",

"C_Cpp.intelliSenseEngine": "Default",
"C_Cpp.enhancedColorization": "Enabled",
"C_Cpp.dimInactiveRegions": true,
"C_Cpp.inactiveRegionOpacity": 0.5,

"[c]": { "editor.semanticHighlighting.enabled": true },
"[cpp]":{ "editor.semanticHighlighting.enabled": true },

"files.associations": {
"mavlink.h": "c",
"system_error": "c",
"chrono": "c",
"common.h": "c",
"array": "c",
"string": "c",
"string_view": "c",
"msp_displayport.h": "c",
"msp.h": "c",
"graphics.h": "c",
"thread": "c",
"mi_rgn.h": "c",
"mi_common.h": "c",
"bitmap.h": "c",
"random": "c",
"format": "c",
"compare": "c",
"cstdint": "c",
"functional": "c",
"rope": "c",
"ranges": "c",
"variant": "c",
"lodepng.h": "c",
"any": "c",
"expected": "c",
"fstream": "c",
"future": "c",
"optional": "c",
"shared_mutex": "c",
"spanstream": "c",
"stacktrace": "c",
"stop_token": "c",
"syncstream": "c",
"tuple": "c",
"string.h": "c",
"mi_vpe.h": "c",
"bitset": "c",
"slist": "c",
"initializer_list": "c",
"span": "c",
"regex": "c",
"utility": "c",
"*.tcc": "c",
"iomanip": "c",
"istream": "c",
"streambuf": "c",
"*.def": "c",
"iterator": "c",
"charconv": "c",
"ratio": "c",
"type_traits": "c",
"hi_math.h": "c",
"cstdlib": "c",
"xlib.h": "c",
"stdbool.h": "c",
"xutil.h": "c",
"xatom.h": "c",
"region.h": "c",
"cairo-xlib.h": "c",
"stdint-uintn.h": "c",
"interface.h": "c",
"valarray": "c",
"complex": "c",
"source_location": "c"
"mavlink.h": "c",
"system_error": "c",
"chrono": "c",
"common.h": "c",
"array": "c",
"string": "c",
"string_view": "c",
"msp_displayport.h": "c",
"msp.h": "c",
"graphics.h": "c",
"thread": "c",
"mi_rgn.h": "c",
"mi_common.h": "c",
"bitmap.h": "c",
"random": "c",
"format": "c",
"compare": "c",
"cstdint": "c",
"functional": "c",
"rope": "c",
"ranges": "c",
"variant": "c",
"lodepng.h": "c",
"any": "c",
"expected": "c",
"fstream": "c",
"future": "c",
"optional": "c",
"shared_mutex": "c",
"spanstream": "c",
"stacktrace": "c",
"stop_token": "c",
"syncstream": "c",
"tuple": "c",
"string.h": "c",
"mi_vpe.h": "c",
"bitset": "c",
"slist": "c",
"initializer_list": "c",
"span": "c",
"regex": "c",
"utility": "c",
"*.tcc": "c",
"iomanip": "c",
"istream": "c",
"streambuf": "c",
"*.def": "c",
"iterator": "c",
"charconv": "c",
"ratio": "c",
"type_traits": "c",
"hi_math.h": "c",
"cstdlib": "c",
"xlib.h": "c",
"stdbool.h": "c",
"xutil.h": "c",
"xatom.h": "c",
"region.h": "c",
"cairo-xlib.h": "c",
"stdint-uintn.h": "c",
"interface.h": "c",
"valarray": "c",
"complex": "c",
"source_location": "c"
}
}
}

71 changes: 48 additions & 23 deletions bmp/lib/schrift.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,14 @@ SFT_Font *sft_loadfile(char const *filename) {
return font;
}

void sft_freefont(SFT_Font *font) {
int sft_freefont(SFT_Font *font) {
if (!font)
return;
return 0;
/* Only unmap if we mapped it ourselves. */
if (font->source == SrcMapping)
unmap_file(font);
free(font);
free(font);
return 1;
}

int sft_lmetrics(const SFT *sft, SFT_LMetrics *metrics) {
Expand Down Expand Up @@ -481,29 +482,53 @@ static void unmap_file(SFT_Font *font) {
#else

static int map_file(SFT_Font *font, const char *filename) {
struct stat info;
int fd;
font->memory = MAP_FAILED;
font->size = 0;
font->source = SrcMapping;
if ((fd = open(filename, O_RDONLY)) < 0) {
return -1;
}
if (fstat(fd, &info) < 0) {
close(fd);
return -1;
}
/* FIXME do some basic validation on info.st_size maybe - it is signed for
* example, so it *could* be negative .. */
font->memory = mmap(NULL, (size_t)info.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
font->size = (uint_fast32_t)info.st_size;
close(fd);
return font->memory == MAP_FAILED ? -1 : 0;
FILE *fp;
size_t n;
long size;

font->memory = NULL;
font->size = 0;
font->source = SrcMapping; /* still mark it so unmap_file knows it should free */

fp = fopen(filename, "rb");
if (!fp)
return -1;

if (fseek(fp, 0, SEEK_END) < 0) {
fclose(fp);
return -1;
}
size = ftell(fp);
if (size < 0) {
fclose(fp);
return -1;
}
rewind(fp);

font->memory = malloc((size_t)size);
if (!font->memory) {
fclose(fp);
return -1;
}

n = fread((void *)font->memory, 1, (size_t)size, fp);
fclose(fp);

if (n != (size_t)size) {
free((void *)font->memory);
font->memory = NULL;
return -1;
}

font->size = (uint_fast32_t)size;
return 0;
}

static void unmap_file(SFT_Font *font) {
assert(font->memory != MAP_FAILED);
munmap((void *)font->memory, font->size);
if (font->memory) {
free((void *)font->memory);
font->memory = NULL;
}
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion bmp/lib/schrift.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const char *sft_version(void);

SFT_Font *sft_loadmem(const void *mem, size_t size);
SFT_Font *sft_loadfile(const char *filename);
void sft_freefont(SFT_Font *font);
int sft_freefont(SFT_Font *font);

int sft_lmetrics(const SFT *sft, SFT_LMetrics *metrics);
int sft_lookup(const SFT *sft, SFT_UChar codepoint, SFT_Glyph *glyph);
Expand Down
45 changes: 45 additions & 0 deletions bmp/macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <stdio.h>
#include <string.h>

#define HAL_DANGER(mod, x, ...) \
do { \
fprintf(stderr, "[%s] \033[31m", (mod)); \
fprintf(stderr, (x), ##__VA_ARGS__); \
fprintf(stderr, "\033[0m"); \
} while (0)

#define HAL_ERROR(mod, x, ...) \
do { \
fprintf(stderr, "[%s] \033[31m", (mod)); \
fprintf(stderr, (x), ##__VA_ARGS__); \
fprintf(stderr, "\033[0m"); \
return EXIT_FAILURE; \
} while (0)

#define HAL_INFO(mod, x, ...) \
do { \
fprintf(stderr, "[%s] ", (mod)); \
fprintf(stderr, (x), ##__VA_ARGS__); \
} while (0)

#define HAL_WARNING(mod, x, ...) \
do { \
fprintf(stderr, "[%s] \033[33m", (mod)); \
fprintf(stderr, (x), ##__VA_ARGS__); \
fprintf(stderr, "\033[0m"); \
} while (0)

#ifndef CEILING
#define CEILING_POS(X) ((X-(int)(X)) > 0 ? (int)(X+1) : (int)(X))
#define CEILING_NEG(X) (int)(X)
#define CEILING(X) ( ((X) > 0) ? CEILING_POS(X) : CEILING_NEG(X) )
#endif

#define EMPTY(x) (x[0] == '\0')
#define ENDS_WITH(a, b) \
((strlen(a) > strlen(b)) && !strcmp(a + strlen(a) - strlen(b), b))
#define EQUALS(a, b) !strcmp(a, b)
#define EQUALS_CASE(a, b) !strcasecmp(a, b)
#define STARTS_WITH(a, b) !strncmp(a, b, strlen(b))
Loading
Loading