mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-21 19:55:00 +00:00
Nobody expects the Ziguanas (#517)
* Add build.zig, remove makefile, add .idea directory to .gitignore * Remove submodules, add projects directly * Remove submodules * Add projects * Rename sub/ to dep/, remove makefiles * Rewrite main.c * Remove Argoat dependency * Remove unused dependencies * Rewrite config.c * Add files * Change default fg to 8 in config.ini * Partially rewrite utils.c * Use Zig package manager * Rewrite INPUTS enum in Zig * Commit unfinished full rewrite (Zig 0.11.0) What needs to be dealt with: - Matrix animation - Authentication part - Testing on actual TTY (not just virtual console) Signed-off-by: AnErrupTion <anerruption@disroot.org> * Implement more (untested) authentication code Signed-off-by: AnErrupTion <anerruption@disroot.org> * Fix some bugs (hopefully) Signed-off-by: AnErrupTion <anerruption@disroot.org> * Try to fix some more bugs Signed-off-by: AnErrupTion <anerruption@disroot.org> * Oops, forgot to allocate hehe Signed-off-by: AnErrupTion <anerruption@disroot.org> * Changes in the Zig rewrite (#596) * Everything * make matrix.zig a bit cleaner * make long lines shorter and add changelog * vi mode * update changelog * get errors from child process and (hopefully) fix some other things * fix utmp entry * run authentication in a child process * update changelog * small code improvements * change that * clear terminal on SIGTERM * Remove LogFile * moved ini to a lib, fixed alternative langs * fix logging out * oops * code improvements * consistency * clearing the env isn't needed anymore (afaik) * replace vi_mode with a bool * type aliases, avoiding zeroes(), breaking a long line * lowercase insert/normal, merge conditionals, code improvements * Add experimental save file migrator + bug fixes + add "-dev" version suffix Signed-off-by: AnErrupTion <anerruption@disroot.org> * Resolve conflicts Signed-off-by: AnErrupTion <anerruption@disroot.org> * Clean up when SIGTERM is received (#597) * clean up child processes on SIGTERM * small code improvement * consistency.. i guess? * Properly set XDG_CURRENT_DESKTOP Signed-off-by: AnErrupTion <anerruption@disroot.org> * Zig 0.12.0 and more! (#599) * less alloc, update migrator, get DesktopNames from .desktop * small cleanup * Update zigini to improve compatibility with old config * Code improvements * Update to zig version 0.12.0 * Some fixes * tiny changes * remove useless comment * migrator changes, and small things * set XDG env vars differently * free memory on error when appending environments * Fix out of bounds issue when using the Delete key Signed-off-by: AnErrupTion <anerruption@disroot.org> * Update zig-ini to fix configuration issue (#603) * Mention display-manager-init for Gentoo/OpenRC in readme.md Signed-off-by: AnErrupTion <anerruption@disroot.org> * Tidy up readme.md Signed-off-by: AnErrupTion <anerruption@disroot.org> * Fix authentication in a few edge cases (#604) * fix loginConv and auth * fix potential mem leak with configs * BIG changes --------- Signed-off-by: AnErrupTion <anerruption@disroot.org> Co-authored-by: アシュ <120780645+Kawaii-Ash@users.noreply.github.com>
This commit is contained in:
195
dep/termbox_next/src/ringbuffer.c
Normal file
195
dep/termbox_next/src/ringbuffer.c
Normal file
@@ -0,0 +1,195 @@
|
||||
#include "ringbuffer.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h> // for ptrdiff_t
|
||||
|
||||
int init_ringbuffer(struct ringbuffer* r, size_t size)
|
||||
{
|
||||
r->buf = (char*)malloc(size);
|
||||
|
||||
if (!r->buf)
|
||||
{
|
||||
return ERINGBUFFER_ALLOC_FAIL;
|
||||
}
|
||||
|
||||
r->size = size;
|
||||
clear_ringbuffer(r);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void free_ringbuffer(struct ringbuffer* r)
|
||||
{
|
||||
free(r->buf);
|
||||
}
|
||||
|
||||
void clear_ringbuffer(struct ringbuffer* r)
|
||||
{
|
||||
r->begin = 0;
|
||||
r->end = 0;
|
||||
}
|
||||
|
||||
size_t ringbuffer_free_space(struct ringbuffer* r)
|
||||
{
|
||||
if (r->begin == 0 && r->end == 0)
|
||||
{
|
||||
return r->size;
|
||||
}
|
||||
|
||||
if (r->begin < r->end)
|
||||
{
|
||||
return r->size - (r->end - r->begin) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return r->begin - r->end - 1;
|
||||
}
|
||||
}
|
||||
|
||||
size_t ringbuffer_data_size(struct ringbuffer* r)
|
||||
{
|
||||
if (r->begin == 0 && r->end == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (r->begin <= r->end)
|
||||
{
|
||||
return r->end - r->begin + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return r->size - (r->begin - r->end) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ringbuffer_push(struct ringbuffer* r, const void* data, size_t size)
|
||||
{
|
||||
if (ringbuffer_free_space(r) < size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (r->begin == 0 && r->end == 0)
|
||||
{
|
||||
memcpy(r->buf, data, size);
|
||||
r->begin = r->buf;
|
||||
r->end = r->buf + size - 1;
|
||||
return;
|
||||
}
|
||||
|
||||
r->end++;
|
||||
|
||||
if (r->begin < r->end)
|
||||
{
|
||||
if ((size_t)(r->buf + (ptrdiff_t)r->size - r->begin) >= size)
|
||||
{
|
||||
// we can fit without cut
|
||||
memcpy(r->end, data, size);
|
||||
r->end += size - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// make a cut
|
||||
size_t s = r->buf + r->size - r->end;
|
||||
memcpy(r->end, data, s);
|
||||
size -= s;
|
||||
memcpy(r->buf, (char*)data + s, size);
|
||||
r->end = r->buf + size - 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(r->end, data, size);
|
||||
r->end += size - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void ringbuffer_pop(struct ringbuffer* r, void* data, size_t size)
|
||||
{
|
||||
if (ringbuffer_data_size(r) < size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int need_clear = 0;
|
||||
|
||||
if (ringbuffer_data_size(r) == size)
|
||||
{
|
||||
need_clear = 1;
|
||||
}
|
||||
|
||||
if (r->begin < r->end)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
memcpy(data, r->begin, size);
|
||||
}
|
||||
|
||||
r->begin += size;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((size_t)(r->buf + (ptrdiff_t)r->size - r->begin) >= size)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
memcpy(data, r->begin, size);
|
||||
}
|
||||
|
||||
r->begin += size;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t s = r->buf + r->size - r->begin;
|
||||
|
||||
if (data)
|
||||
{
|
||||
memcpy(data, r->begin, s);
|
||||
}
|
||||
|
||||
size -= s;
|
||||
|
||||
if (data)
|
||||
{
|
||||
memcpy((char*)data + s, r->buf, size);
|
||||
}
|
||||
|
||||
r->begin = r->buf + size;
|
||||
}
|
||||
}
|
||||
|
||||
if (need_clear)
|
||||
{
|
||||
clear_ringbuffer(r);
|
||||
}
|
||||
}
|
||||
|
||||
void ringbuffer_read(struct ringbuffer* r, void* data, size_t size)
|
||||
{
|
||||
if (ringbuffer_data_size(r) < size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (r->begin < r->end)
|
||||
{
|
||||
memcpy(data, r->begin, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((size_t)(r->buf + (ptrdiff_t)r->size - r->begin) >= size)
|
||||
{
|
||||
memcpy(data, r->begin, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t s = r->buf + r->size - r->begin;
|
||||
memcpy(data, r->begin, s);
|
||||
size -= s;
|
||||
memcpy((char*)data + s, r->buf, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user