cano: 0.1.0-alpha -> 0.2.0-alpha, modernize
This commit is contained in:
parent
52a13583c6
commit
a3e8676a49
42
pkgs/by-name/ca/cano/allow-read-only-store-help-page.patch
Normal file
42
pkgs/by-name/ca/cano/allow-read-only-store-help-page.patch
Normal 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);
|
@ -1,34 +1,55 @@
|
|||||||
{ stdenv
|
{
|
||||||
, lib
|
stdenv,
|
||||||
, fetchFromGitHub
|
lib,
|
||||||
, gnumake
|
fetchFromGitHub,
|
||||||
, ncurses
|
installShellFiles,
|
||||||
|
ncurses,
|
||||||
}:
|
}:
|
||||||
stdenv.mkDerivation (finalAttrs: {
|
stdenv.mkDerivation (finalAttrs: {
|
||||||
pname = "cano";
|
pname = "cano";
|
||||||
version = "0.1.0-alpha";
|
version = "0.2.0-alpha";
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
owner = "CobbCoding1";
|
owner = "CobbCoding1";
|
||||||
repo = "Cano";
|
repo = "Cano";
|
||||||
rev = "v${finalAttrs.version}";
|
rev = "v${finalAttrs.version}";
|
||||||
hash = "sha256-BKbBDN7xZwlNzw7UFgX+PD9UXbr9FtELo+PlbfSHyRY=";
|
hash = "sha256-OaWj0AKw3+sEhcAbIjgOLfxwCKRG6O1k+zSp0GnnFn8=";
|
||||||
};
|
};
|
||||||
|
|
||||||
buildInputs = [ gnumake ncurses ];
|
patches = [ ./allow-read-only-store-help-page.patch ];
|
||||||
hardeningDisable = [ "format" "fortify" ];
|
|
||||||
|
postPatch = ''
|
||||||
|
substituteInPlace src/main.c \
|
||||||
|
--replace-fail "@help@" "${placeholder "out"}/share/help"
|
||||||
|
'';
|
||||||
|
|
||||||
|
nativeBuildInputs = [ installShellFiles ];
|
||||||
|
|
||||||
|
buildInputs = [ ncurses ];
|
||||||
|
|
||||||
|
hardeningDisable = [
|
||||||
|
"format"
|
||||||
|
"fortify"
|
||||||
|
];
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/bin
|
runHook preInstall
|
||||||
cp build/cano $out/bin
|
|
||||||
|
install -Dm755 build/cano -t $out/bin
|
||||||
|
|
||||||
|
mkdir -p $out/share
|
||||||
|
cp -r docs/help $out/share
|
||||||
|
installManPage docs/cano.1
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
description = "Text Editor Written In C Using ncurses";
|
description = "Text Editor Written In C Using ncurses";
|
||||||
homepage = "https://github.com/CobbCoding1/Cano";
|
homepage = "https://github.com/CobbCoding1/Cano";
|
||||||
license = lib.licenses.asl20;
|
license = lib.licenses.asl20;
|
||||||
mainProgram = "Cano";
|
mainProgram = "Cano";
|
||||||
maintainers = with lib.maintainers; [ sigmanificient ];
|
maintainers = with lib.maintainers; [ sigmanificient ];
|
||||||
platforms = lib.platforms.linux;
|
platforms = lib.platforms.linux;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user