[hackers] [surf] Surf now can handle absolute file paths. This allows better local HTML || Christoph Lohmann

From: <hg_AT_suckless.org>
Date: Sun, 25 Nov 2012 22:33:38 +0100 (CET)

changeset: 274:5584d71fa534
tag: tip
user: Christoph Lohmann <20h_AT_r-36.net>
date: Sun Nov 25 22:31:46 2012 +0100
files: config.mk surf.c
description:
Surf now can handle absolute file paths. This allows better local HTML
reading.


diff -r ca10f621494d -r 5584d71fa534 config.mk
--- a/config.mk Tue Nov 20 16:14:28 2012 +0100
+++ b/config.mk Sun Nov 25 22:31:46 2012 +0100
_AT_@ -19,7 +19,7 @@
        -ljavascriptcoregtk-1.0
 
 # flags
-CPPFLAGS = -DVERSION=\"${VERSION}\"
+CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE
 CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
 LDFLAGS = -g ${LIBS}
 
diff -r ca10f621494d -r 5584d71fa534 surf.c
--- a/surf.c Tue Nov 20 16:14:28 2012 +0100
+++ b/surf.c Sun Nov 25 22:31:46 2012 +0100
_AT_@ -13,6 +13,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <limits.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <webkit/webkit.h>
_AT_@ -497,14 +498,23 @@
 
 void
 loaduri(Client *c, const Arg *arg) {
- char *u;
+ char *u, *rp;
         const char *uri = (char *)arg->v;
         Arg a = { .b = FALSE };
 
         if(strcmp(uri, "") == 0)
                 return;
- u = g_strrstr(uri, "://") ? g_strdup(uri)
- : g_strdup_printf("http://%s", uri);
+
+ /* In case it's a file path. */
+ if(uri[0] == '/') {
+ rp = realpath(uri, NULL);
+ u = g_strdup_printf("file://%s", rp);
+ free(rp);
+ } else {
+ u = g_strrstr(uri, "://") ? g_strdup(uri)
+ : g_strdup_printf("http://%s", uri);
+ }
+
         /* prevents endless loop */
         if(c->uri && strcmp(u, c->uri) == 0) {
                 reload(c, &a);
Received on Sun Nov 25 2012 - 22:33:38 CET

This archive was generated by hypermail 2.3.0 : Sun Nov 25 2012 - 22:36:06 CET