💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › 100713b31a89fdf61dc50c3970881… captured on 2023-04-19 at 23:04:21. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2023-09-08)

-=-=-=-=-=-=-

0 /* See LICENSE file for copyright and license details. */

1 #include <pthread.h>

2 #ifdef __linux__

3 #define _GNU_SOURCE

4 #endif

5 #include <signal.h>

6 #include <termbox.h>

7 #include "input.h"

8 #include "gemini.h"

9 #include "display.h"

10 #include "cert.h"

11 #include "sandbox.h"

12 #include <stdio.h>

13 #include <string.h>

14 #include <strings.h>

15 #if defined(__FreeBSD__) || defined(__linux__) || defined(__sun__)

16 #define TTYFD

17 #endif

18

19 int main(int argc, char* argv[]) {

20 #ifdef TTYFD

21 int ttyfd = open("/dev/tty", O_RDWR);

22 if (ttyfd < 0) {

23 printf("Failed to open tty\n");

24 return -1;

25 }

26 #endif

27

28 const char* term = getenv("TERM");

29 if (!term) {

30 printf("Failed to detect terminal\n");

31 #ifdef TTYFD

32 close(ttyfd);

33 #endif

34 return -1;

35 }

36

37 // fix for st

38 if (strcmp("st-256color", term) == 0) {

39 setenv("TERM", "screen-256color", 1);

40 }

41 else if (strcmp("st", term) == 0) {

42 setenv("TERM", "screen", 1);

43 }

44 #ifndef DISABLE_XDG

45 if (!system("which xdg-open > /dev/null 2>&1"))

46 client.xdg = 1;

47 #endif

48

49 if (sandbox_init()) {

50 printf("Failed to sandbox\n");

51 #ifdef TTYFD

52 close(ttyfd);

53 #endif

54 return -1;

55 }

56

57 #ifdef TTYFD

58 if (tb_init_fd(ttyfd) == TB_ERR_INIT_OPEN) {

59 #else

60 if (tb_init() == TB_ERR_INIT_OPEN) {

61 #endif

62 printf("Failed to initialize termbox\n");

63 return -1;

64 }

65

66 if (gmi_init()) return 0;

67 if (tb_set_output_mode(TB_OUTPUT_256)) {

68 printf("Terminal doesn't support 256 colors mode\n");

69 } else client.c256 = 1;

70

71 struct gmi_tab* tab = gmi_newtab_url(NULL);

72 if (argc > 1) {

73 if (gmi_loadfile(tab, argv[1]) <= 0) {

74 gmi_gohome(tab, 1);

75 gmi_request(tab, argv[1], 1);

76 }

77 } else gmi_gohome(tab, 1);

78

79 struct tb_event ev;

80 bzero(&ev, sizeof(ev));

81 int ret = 0;

82 client.tab->scroll = -1;

83

84 while (!client.shutdown) {

85 display();

86 if (!((ret = tb_poll_event(&ev)) == TB_OK || ret == -14) ||

87 input(ev))

88 break;

89 }

90 tb_shutdown();

91 #ifdef TTYFD

92 close(ttyfd);

93 #endif

94 gmi_free();

95 sandbox_close();

96 return 0;

97 }

98