💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › ce11169eb28b91e6a9d044e0358fa… captured on 2023-12-28 at 15:41:57. Gemini links have been rewritten to link to archived content

View Raw

More Information

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

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 "config.h"

11 #define ABOUT_INTERNAL

12 #include "about.h"

13 #define HISTORY_INTERNAL

14 #include "history.h"

15

16 #define MAXIMUM_LIST_LENGTH 2000

17

18 int about_history_param(const char *param) {

19 if (strcmp(param, "clear")) return ERROR_INVALID_ARGUMENT;

20 return history_clear();

21 }

22

23 int about_history(char **out, size_t *length_out) {

24

25 size_t length = 0, i = 0;

26 char *data = NULL;

27 struct history_entry *entry;

28 const char title[] = "# History\n\n=>clear Clear History\n\n";

29

30 if (!(data = dyn_strcat(NULL, &length, V(header)))) goto fail;

31 if (!(data = dyn_strcat(data, &length, V(title)))) goto fail;

32 if (!config.enableHistory) {

33 const char str[] = "History is disabled\n";

34 if (!(data = dyn_strcat(data, &length, V(str)))) goto fail;

35 }

36

37 for (entry = history; entry; entry = entry->next) {

38 char buf[sizeof(*entry)];

39 int len = snprintf(V(buf), "=>%s %s\n",

40 entry->url, entry->title) + 1;

41 if (!(data = dyn_strcat(data, &length, buf, len))) goto fail;

42 if (i++ == MAXIMUM_LIST_LENGTH) break;

43 }

44

45 *out = data;

46 *length_out = length;

47 return 0;

48 fail:

49 free(data);

50 return ERROR_MEMORY_FAILURE;

51 }

52