diff options
| -rw-r--r-- | main.c | 35 |
1 files changed, 23 insertions, 12 deletions
| @@ -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; |