cano: 0.1.0-alpha -> 0.2.0-alpha, modernize

This commit is contained in:
Sigmanificient 2024-08-06 23:20:04 +02:00
parent 52a13583c6
commit a3e8676a49
2 changed files with 80 additions and 17 deletions

View File

@ -0,0 +1,42 @@
diff --git a/src/main.c b/src/main.c
index 993a76f..de5b2c5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,12 +6,8 @@ _Static_assert(sizeof(string_modes)/sizeof(*string_modes) == MODE_COUNT, "Number
char *get_help_page(char *page) {
if (page == NULL) return NULL;
- char *env = getenv("HOME");
- if(env == NULL) CRASH("could not get HOME");
-
- char *help_page = calloc(128, sizeof(char));
- if (help_page == NULL) CRASH("could not calloc memory for help page");
- snprintf(help_page, 128, "%s/.local/share/cano/help/%s", env, page);
+ char *help_page;
+ asprintf(&help_page, "@help@/%s", page);
// check if file exists
struct stat st;
diff --git a/src/tools.c b/src/tools.c
index 220d7a1..4ce211e 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -63,6 +63,9 @@ void free_undo_stack(Undo_Stack *undo) {
void handle_save(Buffer *buffer) {
FILE *file = fopen(buffer->filename, "w");
+
+ if (file == NULL)
+ return;
fwrite(buffer->data.data, buffer->data.count, sizeof(char), file);
fclose(file);
}
@@ -72,7 +75,7 @@ Buffer *load_buffer_from_file(char *filename) {
size_t filename_s = strlen(filename)+1;
buffer->filename = calloc(filename_s, sizeof(char));
strncpy(buffer->filename, filename, filename_s);
- FILE *file = fopen(filename, "a+");
+ FILE *file = fopen(filename, "r");
if(file == NULL) CRASH("Could not open file");
fseek(file, 0, SEEK_END);
size_t length = ftell(file);

View File

@ -1,34 +1,55 @@
{ stdenv
, lib
, fetchFromGitHub
, gnumake
, ncurses
{
stdenv,
lib,
fetchFromGitHub,
installShellFiles,
ncurses,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "cano";
version = "0.1.0-alpha";
version = "0.2.0-alpha";
src = fetchFromGitHub {
owner = "CobbCoding1";
repo = "Cano";
rev = "v${finalAttrs.version}";
hash = "sha256-BKbBDN7xZwlNzw7UFgX+PD9UXbr9FtELo+PlbfSHyRY=";
hash = "sha256-OaWj0AKw3+sEhcAbIjgOLfxwCKRG6O1k+zSp0GnnFn8=";
};
buildInputs = [ gnumake ncurses ];
hardeningDisable = [ "format" "fortify" ];
patches = [ ./allow-read-only-store-help-page.patch ];
postPatch = ''
substituteInPlace src/main.c \
--replace-fail "@help@" "${placeholder "out"}/share/help"
'';
nativeBuildInputs = [ installShellFiles ];
buildInputs = [ ncurses ];
hardeningDisable = [
"format"
"fortify"
];
installPhase = ''
mkdir -p $out/bin
cp build/cano $out/bin
runHook preInstall
install -Dm755 build/cano -t $out/bin
mkdir -p $out/share
cp -r docs/help $out/share
installManPage docs/cano.1
runHook postInstall
'';
meta = {
description = "Text Editor Written In C Using ncurses";
homepage = "https://github.com/CobbCoding1/Cano";
license = lib.licenses.asl20;
mainProgram = "Cano";
maintainers = with lib.maintainers; [ sigmanificient ];
platforms = lib.platforms.linux;
description = "Text Editor Written In C Using ncurses";
homepage = "https://github.com/CobbCoding1/Cano";
license = lib.licenses.asl20;
mainProgram = "Cano";
maintainers = with lib.maintainers; [ sigmanificient ];
platforms = lib.platforms.linux;
};
})