Compare commits

...

2 Commits

Author SHA1 Message Date
d7dc141874 CE fix strange characters appearing at the end of file
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m46s
2026-03-05 21:52:36 +01:00
abc7ac39c1 CE edit status line 2026-03-05 19:58:16 +01:00
8 changed files with 55 additions and 25 deletions

View File

@@ -4,6 +4,7 @@
#include <printf.h>
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
void cprintf (struct context* context, const char* fmt, ...) {
va_list args;
@@ -16,6 +17,7 @@ void cprintf (struct context* context, const char* fmt, ...) {
return;
}
memset (buf, 0, CPRINTF_BUF_MAX);
int len = vsnprintf (buf, CPRINTF_BUF_MAX, fmt, args);
va_end (args);

View File

@@ -77,9 +77,10 @@ static void update_vert_scroll (size_t screen_rows) {
editor.row_offset = editor.cursor.line - (screen_rows - 1) + 1;
}
void edit_start (const char* text) {
void edit_start (const char* file_path, const char* text) {
prepare_lines (text);
struct arena temp_arena;
memset (&temp_arena, 0, sizeof (temp_arena));
size_t cols, rows;
terminal_dimensions (&cols, &rows);
@@ -137,7 +138,7 @@ void edit_start (const char* text) {
bb_remaining -= w;
}
w = snprintf (bbptr, bb_remaining, ANSIQ_SCR_CLR2LEND "\n");
w = snprintf (bbptr, bb_remaining, ANSIQ_SCR_CLR2END "\n");
bbptr += w;
bb_remaining -= w;
@@ -145,6 +146,15 @@ void edit_start (const char* text) {
current_idx++;
}
w = snprintf (bbptr, bb_remaining, ANSIQ_DYN_CUR_SET ANSIQ_SCR_CLR_LINE, (int)rows, 1);
bbptr += w;
bb_remaining -= w;
w = snprintf (bbptr, bb_remaining, "Editing %s; line %zu col %zu", file_path,
editor.cursor.line, editor.cursor.col);
bbptr += w;
bb_remaining -= w;
w = snprintf (bbptr, bb_remaining, ANSIQ_DYN_CUR_SET ANSIQ_CUR_VISIBLE,
(int)(editor.cursor.line - editor.row_offset) + 1,
(int)(editor.cursor.col - editor.col_offset) + 1);

View File

@@ -1,6 +1,6 @@
#ifndef _EDIT_H
#define _EDIT_H
void edit_start (const char* text);
void edit_start (const char* path, const char* text);
#endif // _EDIT_H

View File

@@ -2,6 +2,7 @@
#include "arena_alloc.h"
#include "context.h"
#include "edit.h"
#include "mprintf.h"
#include "parser.h"
#include "self.h"
#include <desc.h>
@@ -235,7 +236,7 @@ static void edit (struct context* context, const char* path_string) {
return;
}
edit_start (str);
edit_start (path_string, str);
volume_close ();
}

View File

@@ -3,6 +3,7 @@
#include <liballoc.h>
#include <printf.h>
#include <stdarg.h>
#include <string.h>
#include <system.h>
void putchar_ (char ch) { (void)ch; }
@@ -18,6 +19,7 @@ void mprintf (const char* fmt, ...) {
return;
}
memset (buf, 0, MPRINTF_BUF_MAX);
int len = vsnprintf (buf, MPRINTF_BUF_MAX, fmt, args);
va_end (args);

View File

@@ -25,31 +25,39 @@ static struct tar_file* tar_get_file (struct tarfs* tarfs, const char* filename)
static size_t tar_get_size (uint8_t* in) {
size_t size = 0;
size_t j;
size_t count = 1;
for (size_t i = 0; i < 11; i++) {
if (in[i] < '0' || in[i] > '7')
break;
for (j = 11; j > 0; j--, count *= 8)
size += ((in[j - 1] - '0') * count);
size = (size * 8) + (in[i] - '0');
}
return size;
}
static size_t tar_parse (struct tarfs* tarfs, uint8_t* addr) {
static size_t tar_parse (struct tarfs* tarfs, uint8_t* addr, size_t max_size) {
size_t i;
uint8_t* ptr = addr;
for (i = 0; i < TARFS_FILES_MAX; i++) {
struct tar_header* hdr = (struct tar_header*)addr;
struct tar_header* hdr = (struct tar_header*)ptr;
if (hdr->filename[0] == '\0')
break;
if ((size_t)(ptr - addr) + 512 > max_size)
break;
size_t size = tar_get_size (hdr->size);
tarfs->tarfs_files[i].header = hdr;
tarfs->tarfs_files[i].content = (uint8_t*)((uintptr_t)hdr + 512);
tarfs->tarfs_files[i].size = tar_get_size ((uint8_t*)hdr->size);
tarfs->tarfs_files[i].content = ptr + 512;
tarfs->tarfs_files[i].size = size;
addr += 512 + ((size + 511) & ~511);
ptr += 512 + ((size + 511) & ~511);
if ((size_t)(ptr - addr) > max_size)
break;
}
return i;
@@ -92,6 +100,7 @@ int tarfs_mount (struct vfs_volume* volume, bool format) {
if (buffer == NULL) {
spin_unlock (&back_device->lock);
free (volume->udata);
volume->udata = NULL;
return ret;
}
@@ -105,12 +114,14 @@ int tarfs_mount (struct vfs_volume* volume, bool format) {
if (ret < 0) {
free (buffer);
free (volume->udata);
volume->udata = NULL;
return ret;
}
tarfs->buffer = buffer;
tar_parse (tarfs, tarfs->buffer);
tar_parse (tarfs, tarfs->buffer, total_size);
return ret;
}
@@ -166,6 +177,9 @@ int tarfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffe
if (file == NULL)
return -ST_NOT_FOUND;
if (off >= file->size)
return -ST_OOB_ERROR;
memcpy (buffer, (void*)((uintptr_t)file->content + off), min (size, file->size));
return ST_OK;
@@ -183,19 +197,21 @@ int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct di
size_t entry_counter = 0;
for (size_t i = 0; i < TARFS_FILES_MAX; i++) {
if ((tarfs->tarfs_files[i].header != NULL) && (entry_num == entry_counter)) {
if (tarfs->tarfs_files[i].header != NULL) {
if (entry_num == entry_counter) {
tar_file = &tarfs->tarfs_files[i];
break;
}
entry_counter++;
}
}
if (tar_file != NULL) {
sprintf (entry->path, "/%s", tar_file->header->filename);
return ST_NOT_DIR;
return ST_OK;
}
return ST_DIR_NO_ENTRIES;
return -ST_DIR_NO_ENTRIES;
}
int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,

View File

@@ -49,17 +49,16 @@ int memcmp (const void* s1, const void* s2, size_t n) {
void strtokenize (const char* str, char delim, void* ctx, strtokenize_cb_func_t cb) {
const char* start = str;
const char* end;
while (*start) {
while (*start == delim && *start)
while (*start && *start == delim)
start++;
if (!*start)
break;
end = start;
while (*end != delim && *end)
const char* end = start;
while (*end && *end != delim)
end++;
if (!cb (ctx, start, (size_t)(end - start)))

View File

@@ -9,7 +9,7 @@
#define ANSIQ_SCR_CLR_SAV ANSIQ_ESC"[3J" // Clear saved lines
#define ANSIQ_SCR_CLR2LEND ANSIQ_ESC"[0K" // Clear to end of line
#define ANSIQ_SCR_CLR2LBEG ANSIQ_ESC"[1K" // Clear to begining of line
#define ANSIQ_SCR_CLR_LINE ANSIQ_ESC"[1K" // Clear entire line
#define ANSIQ_SCR_CLR_LINE ANSIQ_ESC"[2K" // Clear entire line
#define ANSIQ_SCR_RESTORE ANSIQ_ESC"[?47l"
#define ANSIQ_SCR_SAVE ANSIQ_ESC"[?47h"
/* clang-format on */