summaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
authorGravatar default2024-03-25 15:33:14 +0100
committerGravatar default2024-03-25 15:33:14 +0100
commitbc752b7d67d834455eae9eacec16e28585c79c5f (patch)
tree545f468d13dd9a5000178ec364e8c60c4819a188 /format.c
parentAdded an additional check for blocked instances. (diff)
downloadpenes-snac2-bc752b7d67d834455eae9eacec16e28585c79c5f.tar.gz
penes-snac2-bc752b7d67d834455eae9eacec16e28585c79c5f.tar.xz
penes-snac2-bc752b7d67d834455eae9eacec16e28585c79c5f.zip
Emojis are now read from ~/emojis.json.
Diffstat (limited to '')
-rw-r--r--format.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/format.c b/format.c
index 9944822..06e006a 100644
--- a/format.c
+++ b/format.c
@@ -5,6 +5,7 @@
5#include "xs_regex.h" 5#include "xs_regex.h"
6#include "xs_mime.h" 6#include "xs_mime.h"
7#include "xs_html.h" 7#include "xs_html.h"
8#include "xs_json.h"
8 9
9#include "snac.h" 10#include "snac.h"
10 11
@@ -36,6 +37,39 @@ const char *smileys[] = {
36}; 37};
37 38
38 39
40xs_dict *emojis(void)
41/* returns a dict with the emojis */
42{
43 xs *fn = xs_fmt("%s/emojis.json", srv_basedir);
44 FILE *f;
45
46 if (mtime(fn) == 0) {
47 /* file does not exist; create it with the defaults */
48 xs *d = xs_dict_new();
49 const char **emo = smileys;
50
51 while (*emo) {
52 d = xs_dict_append(d, emo[0], emo[1]);
53 emo += 2;
54 }
55
56 if ((f = fopen(fn, "w")) != NULL) {
57 xs_json_dump(d, 4, f);
58 fclose(f);
59 }
60 }
61
62 xs_dict *d = NULL;
63
64 if ((f = fopen(fn, "r")) != NULL) {
65 d = xs_json_load(f);
66 fclose(f);
67 }
68
69 return d;
70}
71
72
39static xs_str *format_line(const char *line, xs_list **attach) 73static xs_str *format_line(const char *line, xs_list **attach)
40/* formats a line */ 74/* formats a line */
41{ 75{
@@ -190,11 +224,12 @@ xs_str *not_really_markdown(const char *content, xs_list **attach)
190 224
191 { 225 {
192 /* traditional emoticons */ 226 /* traditional emoticons */
193 const char **emo = smileys; 227 xs *d = emojis();
228 int c = 0;
229 char *k, *v;
194 230
195 while (*emo) { 231 while (xs_dict_next(d, &k, &v, &c)) {
196 s = xs_replace_i(s, emo[0], emo[1]); 232 s = xs_replace_i(s, k, v);
197 emo += 2;
198 } 233 }
199 } 234 }
200 235