aboutsummaryrefslogtreecommitdiff
path: root/src/vtab.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vtab.c')
-rw-r--r--src/vtab.c71
1 files changed, 68 insertions, 3 deletions
diff --git a/src/vtab.c b/src/vtab.c
index e02ebe7..6a23541 100644
--- a/src/vtab.c
+++ b/src/vtab.c
@@ -16,6 +16,71 @@
#include "wydawca.h"
+struct wy_url {
+ char *printable;
+ char *scheme;
+ char *path;
+};
+
+wy_url_t
+wy_url_create(const char *str)
+{
+ wy_url_t url;
+
+ url = grecs_zalloc(sizeof(url[0]));
+ url->printable = grecs_strdup(str);
+ if (*str == '/') {
+ url->scheme = grecs_strdup("file");
+ url->path = grecs_strdup(str);
+ } else {
+ size_t len = strcspn(str, ":");
+ if (!str[len]) {
+ wy_url_free(url);
+ errno = EINVAL;
+ return NULL;
+ }
+ url->scheme = grecs_malloc(len + 1);
+ memcpy(url->scheme, str, len);
+ url->scheme[len] = 0;
+
+ if (str[len + 1] && strncmp(str + len + 1, "//", 2) == 0)
+ len += 2;
+ if (str[len + 1])
+ url->path = grecs_strdup(str + len + 1);
+ else
+ url->path = NULL;
+ }
+ return url;
+}
+
+void
+wy_url_free(wy_url_t url)
+{
+ free(url->printable);
+ free(url->scheme);
+ free(url->path);
+ free(url);
+}
+
+const char *
+wy_url_path(wy_url_t url)
+{
+ return url->path;
+}
+
+const char *
+wy_url_scheme(wy_url_t url)
+{
+ return url->scheme;
+}
+
+const char *
+wy_url_printable(wy_url_t url)
+{
+ return url->printable;
+}
+
+
struct virt_tab_reg {
char *scheme;
struct virt_tab vtab;
@@ -35,12 +100,12 @@ static struct virt_tab_reg reg[] = {
};
int
-url_to_vtab(mu_url_t url, struct virt_tab *vtab)
+url_to_vtab(wy_url_t url, struct virt_tab *vtab)
{
- const char *scheme;
+ const char *scheme = wy_url_scheme(url);
int i;
- if (mu_url_sget_scheme(url, &scheme))
+ if (!scheme)
return 1;
for (i = 0; reg[i].scheme; i++)
if (strcmp(reg[i].scheme, scheme) == 0) {

Return to:

Send suggestions and report system problems to the System administrator.