Unverified Commit 6fde146e authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

Merge pull request #332828 from Sigmanificient/cano

cano: 0.1.0-alpha -> 0.2.0-alpha, modernize
parents 6ae623ba a3e8676a
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
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);
+38 −17
Original line number Diff line number Diff line
{ 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 = {