summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2025-02-14 10:24:13 +0100
committerGravatar default2025-02-14 10:24:13 +0100
commite020ca84718d99401a99af0363992b4661a1d16e (patch)
tree9f980740c02571278be678630c84b85e19b6a979
parenthtml_footer() now receives an optional snac *user argument. (diff)
downloadpenes-snac2-e020ca84718d99401a99af0363992b4661a1d16e.tar.gz
penes-snac2-e020ca84718d99401a99af0363992b4661a1d16e.tar.xz
penes-snac2-e020ca84718d99401a99af0363992b4661a1d16e.zip
xs_po.h new file.
-rw-r--r--Makefile14
-rw-r--r--Makefile.NetBSD14
-rw-r--r--data.c1
-rw-r--r--snac.c1
-rw-r--r--xs_po.h86
-rw-r--r--xs_version.h2
6 files changed, 103 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 1fddbb2..178cfdd 100644
--- a/Makefile
+++ b/Makefile
@@ -44,20 +44,20 @@ activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \
44 xs_openssl.h xs_regex.h xs_time.h xs_set.h xs_match.h xs_unicode.h \ 44 xs_openssl.h xs_regex.h xs_time.h xs_set.h xs_match.h xs_unicode.h \
45 snac.h http_codes.h 45 snac.h http_codes.h
46data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \ 46data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \
47 xs_set.h xs_time.h xs_regex.h xs_match.h xs_unicode.h xs_random.h snac.h \ 47 xs_set.h xs_time.h xs_regex.h xs_match.h xs_unicode.h xs_random.h \
48 http_codes.h 48 xs_po.h snac.h http_codes.h
49format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \ 49format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \
50 xs_time.h xs_match.h snac.h http_codes.h 50 xs_time.h xs_match.h snac.h http_codes.h
51html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \ 51html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \
52 xs_time.h xs_mime.h xs_match.h xs_html.h xs_curl.h xs_unicode.h snac.h \ 52 xs_time.h xs_mime.h xs_match.h xs_html.h xs_curl.h xs_unicode.h xs_url.h \
53 http_codes.h 53 snac.h http_codes.h
54http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \ 54http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
55 snac.h http_codes.h 55 snac.h http_codes.h
56httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \ 56httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \
57 xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h \ 57 xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h \
58 http_codes.h 58 http_codes.h
59main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h \ 59main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \
60 http_codes.h 60 snac.h http_codes.h
61mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \ 61mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
62 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \ 62 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
63 snac.h http_codes.h 63 snac.h http_codes.h
@@ -65,7 +65,7 @@ sandbox.o: sandbox.c xs.h snac.h http_codes.h
65snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \ 65snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \
66 xs_json.h xs_curl.h xs_openssl.h xs_socket.h xs_unix_socket.h xs_url.h \ 66 xs_json.h xs_curl.h xs_openssl.h xs_socket.h xs_unix_socket.h xs_url.h \
67 xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h xs_random.h \ 67 xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h xs_random.h \
68 xs_match.h xs_fcgi.h xs_html.h snac.h http_codes.h 68 xs_match.h xs_fcgi.h xs_html.h xs_po.h snac.h http_codes.h
69upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h http_codes.h 69upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h http_codes.h
70utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \ 70utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \
71 xs_random.h xs_glob.h xs_curl.h xs_regex.h snac.h http_codes.h 71 xs_random.h xs_glob.h xs_curl.h xs_regex.h snac.h http_codes.h
diff --git a/Makefile.NetBSD b/Makefile.NetBSD
index 93222b2..51c8181 100644
--- a/Makefile.NetBSD
+++ b/Makefile.NetBSD
@@ -39,20 +39,20 @@ activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \
39 xs_openssl.h xs_regex.h xs_time.h xs_set.h xs_match.h xs_unicode.h \ 39 xs_openssl.h xs_regex.h xs_time.h xs_set.h xs_match.h xs_unicode.h \
40 snac.h http_codes.h 40 snac.h http_codes.h
41data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \ 41data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \
42 xs_set.h xs_time.h xs_regex.h xs_match.h xs_unicode.h xs_random.h snac.h \ 42 xs_set.h xs_time.h xs_regex.h xs_match.h xs_unicode.h xs_random.h \
43 http_codes.h 43 xs_po.h snac.h http_codes.h
44format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \ 44format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \
45 xs_time.h xs_match.h snac.h http_codes.h 45 xs_time.h xs_match.h snac.h http_codes.h
46html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \ 46html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \
47 xs_time.h xs_mime.h xs_match.h xs_html.h xs_curl.h xs_unicode.h snac.h \ 47 xs_time.h xs_mime.h xs_match.h xs_html.h xs_curl.h xs_unicode.h xs_url.h \
48 http_codes.h 48 snac.h http_codes.h
49http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \ 49http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
50 snac.h http_codes.h 50 snac.h http_codes.h
51httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \ 51httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \
52 xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h \ 52 xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h \
53 http_codes.h 53 http_codes.h
54main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h \ 54main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \
55 http_codes.h 55 snac.h http_codes.h
56mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \ 56mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
57 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \ 57 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
58 snac.h http_codes.h 58 snac.h http_codes.h
@@ -60,7 +60,7 @@ sandbox.o: sandbox.c xs.h snac.h http_codes.h
60snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \ 60snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \
61 xs_json.h xs_curl.h xs_openssl.h xs_socket.h xs_unix_socket.h xs_url.h \ 61 xs_json.h xs_curl.h xs_openssl.h xs_socket.h xs_unix_socket.h xs_url.h \
62 xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h xs_random.h \ 62 xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h xs_random.h \
63 xs_match.h xs_fcgi.h xs_html.h snac.h http_codes.h 63 xs_match.h xs_fcgi.h xs_html.h xs_po.h snac.h http_codes.h
64upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h http_codes.h 64upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h http_codes.h
65utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \ 65utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \
66 xs_random.h xs_glob.h xs_curl.h xs_regex.h snac.h http_codes.h 66 xs_random.h xs_glob.h xs_curl.h xs_regex.h snac.h http_codes.h
diff --git a/data.c b/data.c
index 3aba471..f935b39 100644
--- a/data.c
+++ b/data.c
@@ -13,6 +13,7 @@
13#include "xs_match.h" 13#include "xs_match.h"
14#include "xs_unicode.h" 14#include "xs_unicode.h"
15#include "xs_random.h" 15#include "xs_random.h"
16#include "xs_po.h"
16 17
17#include "snac.h" 18#include "snac.h"
18 19
diff --git a/snac.c b/snac.c
index 541828e..d4a96e9 100644
--- a/snac.c
+++ b/snac.c
@@ -24,6 +24,7 @@
24#include "xs_match.h" 24#include "xs_match.h"
25#include "xs_fcgi.h" 25#include "xs_fcgi.h"
26#include "xs_html.h" 26#include "xs_html.h"
27#include "xs_po.h"
27 28
28#include "snac.h" 29#include "snac.h"
29 30
diff --git a/xs_po.h b/xs_po.h
new file mode 100644
index 0000000..c6feec9
--- /dev/null
+++ b/xs_po.h
@@ -0,0 +1,86 @@
1/* copyright (c) 2025 grunfink et al. / MIT license */
2
3#ifndef _XS_PO_H
4
5#define _XS_PO_H
6
7xs_dict *xs_po_to_dict(const char *fn);
8
9#ifdef XS_IMPLEMENTATION
10
11xs_dict *xs_po_to_dict(const char *fn)
12/* converts a PO file to a dict */
13{
14 xs_dict *d = NULL;
15 FILE *f;
16
17 if ((f = fopen(fn, "r")) != NULL) {
18 d = xs_dict_new();
19
20 xs *k = NULL;
21 xs *v = NULL;
22 enum { IN_NONE, IN_K, IN_V } mode = IN_NONE;
23
24 while (!feof(f)) {
25 xs *l = xs_strip_i(xs_readline(f));
26
27 /* discard empty lines and comments */
28 if (*l == '\0' || *l == '#')
29 continue;
30
31 if (xs_startswith(l, "msgid ")) {
32 if (mode == IN_V) {
33 /* flush */
34 if (xs_is_string(k) && xs_is_string(v) && *v)
35 d = xs_dict_set(d, k, v);
36
37 k = xs_free(k);
38 v = xs_free(v);
39 }
40
41 l = xs_replace_i(l, "msgid ", "");
42 mode = IN_K;
43
44 k = xs_str_new(NULL);
45 }
46 else
47 if (xs_startswith(l, "msgstr ")) {
48 if (mode != IN_K)
49 break;
50
51 l = xs_replace_i(l, "msgstr ", "");
52 mode = IN_V;
53
54 v = xs_str_new(NULL);
55 }
56
57 l = xs_replace_i(l, "\\n", "\n");
58 l = xs_strip_chars_i(l, "\"");
59
60 switch (mode) {
61 case IN_K:
62 k = xs_str_cat(k, l);
63 break;
64
65 case IN_V:
66 v = xs_str_cat(v, l);
67 break;
68
69 case IN_NONE:
70 break;
71 }
72 }
73
74 /* final flush */
75 if (xs_is_string(k) && xs_is_string(v) && *v)
76 d = xs_dict_set(d, k, v);
77
78 fclose(f);
79 }
80
81 return d;
82}
83
84#endif /* XS_IMPLEMENTATION */
85
86#endif /* XS_PO_H */
diff --git a/xs_version.h b/xs_version.h
index 7314133..f899dcb 100644
--- a/xs_version.h
+++ b/xs_version.h
@@ -1 +1 @@
/* 2f43b93e9d2b63360c802e09f4c68adfef74c673 2025-01-28T07:40:50+01:00 */ /* d467dc71e518603250a55c8a67e26cf40e1710e9 2025-02-14T10:21:15+01:00 */