diff --git a/Makefile b/Makefile index ca33810..87ff32d 100644 --- a/Makefile +++ b/Makefile @@ -16,14 +16,15 @@ dep: activitypub.o: activitypub.c xs.h xs_encdec.h xs_json.h xs_curl.h \ xs_mime.h xs_openssl.h xs_regex.h xs_time.h snac.h -data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h snac.h +data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h xs_glob.h snac.h html.o: html.c xs.h xs_io.h xs_encdec.h xs_json.h xs_regex.h xs_set.h \ - xs_openssl.h snac.h + xs_openssl.h xs_time.h snac.h http.o: http.c xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h xs_time.h \ snac.h httpd.o: httpd.c xs.h xs_io.h xs_encdec.h xs_json.h xs_socket.h \ xs_httpd.h snac.h main.o: main.c xs.h xs_io.h xs_encdec.h xs_json.h snac.h snac.o: snac.c xs.h xs_io.h xs_encdec.h xs_json.h xs_curl.h xs_openssl.h \ - xs_socket.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h snac.h + xs_socket.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h \ + snac.h webfinger.o: webfinger.c xs.h xs_encdec.h xs_json.h xs_curl.h snac.h diff --git a/data.c b/data.c index 5e0ea66..b19d1c6 100644 --- a/data.c +++ b/data.c @@ -5,6 +5,7 @@ #include "xs_io.h" #include "xs_json.h" #include "xs_openssl.h" +#include "xs_glob.h" #include "snac.h" @@ -144,46 +145,6 @@ int user_open(snac *snac, char *uid) } -d_char *xs_glob_n(const char *spec, int basename, int reverse, int max) -/* does a globbing and returns the found files */ -{ - glob_t globbuf; - d_char *list = xs_list_new(); - - if (glob(spec, 0, NULL, &globbuf) == 0) { - int n; - - if (max > globbuf.gl_pathc) - max = globbuf.gl_pathc; - - for (n = 0; n < max; n++) { - char *p; - - if (reverse) - p = globbuf.gl_pathv[globbuf.gl_pathc - n - 1]; - else - p = globbuf.gl_pathv[n]; - - if (p != NULL) { - if (basename) { - if ((p = strrchr(p, '/')) == NULL) - continue; - - p++; - } - - list = xs_list_append(list, p); - } - } - } - - globfree(&globbuf); - - return list; -} -#define xs_glob(spec, basename, reverse) xs_glob_n(spec, basename, reverse, 0xfffffff) - - d_char *user_list(void) /* returns the list of user ids */ { diff --git a/snac.c b/snac.c index 93b4e05..86a4c4f 100644 --- a/snac.c +++ b/snac.c @@ -15,6 +15,7 @@ #include "xs_regex.h" #include "xs_set.h" #include "xs_time.h" +#include "xs_glob.h" #include "snac.h" diff --git a/xs_glob.h b/xs_glob.h new file mode 100644 index 0000000..c5293dc --- /dev/null +++ b/xs_glob.h @@ -0,0 +1,56 @@ +/* copyright (c) 2022 grunfink - MIT license */ + +#ifndef _XS_GLOB_H + +#define _XS_GLOB_H + +d_char *xs_glob_n(const char *spec, int basename, int reverse, int max); +#define xs_glob(spec, basename, reverse) xs_glob_n(spec, basename, reverse, 0xfffffff) + + +#ifdef XS_IMPLEMENTATION + +#include + +d_char *xs_glob_n(const char *spec, int basename, int reverse, int max) +/* does a globbing and returns the found files */ +{ + glob_t globbuf; + d_char *list = xs_list_new(); + + if (glob(spec, 0, NULL, &globbuf) == 0) { + int n; + + if (max > globbuf.gl_pathc) + max = globbuf.gl_pathc; + + for (n = 0; n < max; n++) { + char *p; + + if (reverse) + p = globbuf.gl_pathv[globbuf.gl_pathc - n - 1]; + else + p = globbuf.gl_pathv[n]; + + if (p != NULL) { + if (basename) { + if ((p = strrchr(p, '/')) == NULL) + continue; + + p++; + } + + list = xs_list_append(list, p); + } + } + } + + globfree(&globbuf); + + return list; +} + + +#endif /* XS_IMPLEMENTATION */ + +#endif /* _XS_GLOB_H */