summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar grunfink2025-02-05 09:18:29 +0000
committerGravatar grunfink2025-02-05 09:18:29 +0000
commitacfe4b4fb539a138428dfba1047cde8da747916f (patch)
treec9c510a70471ebcc209ffe5af290b3cf4cd30515
parentMerge pull request 'Fix link detection. Fixes: #290' (#296) from inz/snac2:li... (diff)
parentAllow multiple editors at the same time (diff)
downloadsnac2-acfe4b4fb539a138428dfba1047cde8da747916f.tar.gz
snac2-acfe4b4fb539a138428dfba1047cde8da747916f.tar.xz
snac2-acfe4b4fb539a138428dfba1047cde8da747916f.zip
Merge pull request 'Allow multiple editors at the same time' (#297) from inz/snac2:temp-file into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/297
-rw-r--r--main.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/main.c b/main.c
index 347c495..58a46de 100644
--- a/main.c
+++ b/main.c
@@ -676,19 +676,25 @@ int main(int argc, char *argv[])
676 676
677 if (strcmp(url, "-e") == 0) { 677 if (strcmp(url, "-e") == 0) {
678 /* get the content from an editor */ 678 /* get the content from an editor */
679#define EDITOR "$EDITOR "
680 char cmd[] = EDITOR "/tmp/snac-XXXXXX";
679 FILE *f; 681 FILE *f;
680 682 int fd = mkstemp(cmd + strlen(EDITOR));
681 unlink("/tmp/snac-edit.txt"); 683
682 system("$EDITOR /tmp/snac-edit.txt"); 684 if (fd >= 0) {
683 685 int status = system(cmd);
684 if ((f = fopen("/tmp/snac-edit.txt", "r")) != NULL) { 686
685 content = xs_readall(f); 687 if (WIFEXITED(status) && WEXITSTATUS(status) == 0 && (f = fdopen(fd, "r")) != NULL) {
686 fclose(f); 688 content = xs_readall(f);
687 689 fclose(f);
688 unlink("/tmp/snac-edit.txt"); 690 unlink(cmd + strlen(EDITOR));
689 } 691 } else {
690 else { 692 printf("Nothing to send\n");
691 printf("Nothing to send\n"); 693 close(fd);
694 return 1;
695 }
696 } else {
697 fprintf(stderr, "Temp file creation failed\n");
692 return 1; 698 return 1;
693 } 699 }
694 } 700 }
@@ -700,6 +706,11 @@ int main(int argc, char *argv[])
700 else 706 else
701 content = xs_dup(url); 707 content = xs_dup(url);
702 708
709 if (!content || !*content) {
710 printf("Nothing to send\n");
711 return 1;
712 }
713
703 int scope = 0; 714 int scope = 0;
704 if (strcmp(cmd, "note_mention") == 0) 715 if (strcmp(cmd, "note_mention") == 0)
705 scope = 1; 716 scope = 1;