💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › d31136dca49049225c2f817375ae5… captured on 2023-01-29 at 04:00:38. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-07-16)

🚧 View Differences

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

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

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

17 #ifdef MEM_CHECK

18 __init();

19 #endif

20

21 #if defined(__FreeBSD__) || defined(__linux__)

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

23 if (ttyfd < 0) {

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

25 return -1;

26 }

27 #endif

28

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

30 if (!term) {

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

32 #if defined(__FreeBSD__) || defined(__linux__)

33 close(ttyfd);

34 #endif

35 return -1;

36 }

37

38 // fix for st

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

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

41 }

42 if (strcmp("st", term) == 0) {

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

44 }

45 #ifndef DISABLE_XDG

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

47 client.xdg = 1;

48 #endif

49

50 if (sandbox_init()) {

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

52 #if defined(__FreeBSD__) || defined(__linux__)

53 close(ttyfd);

54 #endif

55 return -1;

56 }

57

58 #if defined(__FreeBSD__) || defined(__linux__)

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

60 #else

61 if (tb_init() == TB_ERR_INIT_OPEN) {

62 #endif

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

64 return -1;

65 }

66

67 if (gmi_init()) return 0;

68 #ifdef TERMINAL_IMG_VIEWER

69 if (tb_set_output_mode(TB_OUTPUT_256)) {

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

71 gmi_free();

72 #if defined(__FreeBSD__) || defined(__linux__)

73 close(ttyfd);

74 #endif

75 return -1;

76 }

77 client.c256 = 1;

78 #endif

79

80

81

82 struct gmi_tab* tab = gmi_newtab_url(NULL);

83 if (argc > 1) {

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

85 gmi_gohome(tab, 1);

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

87 }

88 } else gmi_gohome(tab, 1);

89

90 struct tb_event ev;

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

92 int ret = 0;

93 client.tabs[client.tab].scroll = -1;

94

95 while (!client.shutdown) {

96 display();

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

98 break;

99 }

100 if (input(ev)) break;

101 }

102 tb_shutdown();

103 #if defined(__FreeBSD__) || defined(__linux__)

104 close(ttyfd);

105 #endif

106 gmi_free();

107 sandbox_close();

108 #ifdef MEM_CHECK

109 __check();

110 #endif

111 return 0;

112 }

113