💾 Archived View for gemini.rmf-dev.com › repo › Vaati › VgmiTL › files › 23fc39f5012db668f0627b92ee6… captured on 2022-07-16 at 17:13:21. Gemini links have been rewritten to link to archived content

View Raw

More Information

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

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

1 #define TB_IMPL

2 #include <signal.h>

3 #include <termbox.h>

4 #include "input.h"

5 #include "gemini.h"

6 #include "display.h"

7 #include "cert.h"

8 #include <stdio.h>

9 #include <string.h>

10 #include <strings.h>

11

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

13 #ifdef MEM_CHECK

14 __init();

15 #endif

16 #ifdef __OpenBSD__

17 #ifndef HIDE_HOME

18 char path[1024];

19 if (gethomefolder(path, sizeof(path)) < 1) {

20 printf("Failed to get home folder\n");

21 return -1;

22 }

23 #endif

24 char certpath[1024];

25 if (getcachefolder(certpath, sizeof(certpath)) < 1) {

26 printf("Failed to get cache folder\n");

27 return -1;

28 }

29 tb_init();

30 if (

31 #ifndef HIDE_HOME

32 unveil(path, "r") ||

33 #endif

34 unveil(certpath, "rwc") ||

35 #ifndef DISABLE_XDG

36 unveil("/bin/sh", "x") ||

37 unveil("/usr/bin/which", "x") ||

38 unveil("/usr/local/bin/xdg-open", "x") ||

39 #endif

40 unveil("/etc/resolv.conf", "r") ||

41 unveil(NULL, NULL)) {

42 printf("Failed to unveil\n");

43 return -1;

44 }

45 #ifndef DISABLE_XDG

46 if (pledge("stdio rpath wpath cpath inet dns tty exec proc", NULL)) {

47 #else

48 if (pledge("stdio rpath wpath cpath inet dns tty", NULL)) {

49 #endif

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

51 return -1;

52 }

53 #endif

54 if (gmi_init()) return 0;

55 gmi_newtab();

56 if (argc > 1) {

57 if (gmi_loadfile(argv[1]) > 0)

58 gmi_load(&client.tabs[client.tab].page);

59 else if (gmi_request(argv[1]) > 0) {

60 client.tabs[0].error[0] = '\0';

61 client.input.error = 0;

62 }

63 }

64

65 #ifndef __OpenBSD__

66 tb_init();

67 #endif

68

69 #ifdef TERMINAL_IMG_VIEWER

70 if (tb_set_output_mode(TB_OUTPUT_256)) {

71 gmi_free();

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

73 return -1;

74 }

75 client.c256 = 1;

76 #endif

77

78 struct tb_event ev;

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

80 int ret = 0;

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

82

83 while (1) {

84 display();

85 client.refresh = 0;

86 norefresh:

87 if (!((ret = tb_peek_event(&ev, 100)) == TB_OK ||

88 ret == TB_ERR_POLL ||

89 ret == TB_ERR_NO_EVENT)) {

90 break;

91 }

92 if (ret == TB_ERR_NO_EVENT && !client.refresh) goto norefresh;

93 if (input(ev)) break;

94 }

95 tb_shutdown();

96 gmi_free();

97 #ifdef MEM_CHECK

98 __check();

99 #endif

100 return 0;

101 }

102