Go Back

0 /*

1 * ISC License

2 * Copyright (c) 2023 RMF <rawmonk@firemail.cc>

3 */

4 #include <stdio.h>

5 #include <stdlib.h>

6 #include <string.h>

7 #include "macro.h"

8 #include "strlcpy.h"

9 #include "error.h"

10 #include "bookmarks.h"

11 #define ABOUT_INTERNAL

12 #include "about.h"

13

14 char newtab_page_header[] =

15 HEADER \

16 "# Vgmi - " VERSION "\n\n" \

17 "A Gemini client written in C with vim-like keybindings\n\n## Bookmarks\n\n";

18

19 int about_newtab(char **out, size_t *length_out) {

20 size_t length = 0, i;

21 char *data = NULL;

22 if (!(data = dyn_strcat(NULL, &length, V(newtab_page_header))))

23 goto fail;

24 for (i = 0; i < bookmark_length; i++) {

25 char line[sizeof(struct bookmark) + 8];

26 size_t line_length;

27 line_length = snprintf(V(line), "=>%s %s\n",

28 bookmarks[i].url, bookmarks[i].name);

29 if (!(data = dyn_strcat(data, &length, line, line_length)))

30 goto fail;

31 }

32 if (!(data = dyn_strcat(data, &length, V("\n")))) goto fail;

33 if (!(data = dyn_strcat(data, &length, V(HELP_INFO)))) goto fail;

34

35 *out = data;

36 *length_out = length;

37 return 0;

38 fail:

39 free(data);

40 return ERROR_MEMORY_FAILURE;

41 }

42