r5416 dsilvers - in /branches/vince/netsurf-fb: Makefile Makefile.config Makefile.sources framebuffer/fb_findfile.c framebuffer/fb_findfile.h framebuffer/fb_frontend_ablefb.c framebuffer/fb_frontend_linuxfb.c framebuffer/fb_gui.c

netsurf at semichrome.net netsurf at semichrome.net
Tue Sep 23 12:05:02 BST 2008


Author: dsilvers
Date: Tue Sep 23 06:05:00 2008
New Revision: 5416

URL: http://source.netsurf-browser.org?rev=5416&view=rev
Log:
Rationalise how the framebuffer frontend finds resources and options

Added:
    branches/vince/netsurf-fb/framebuffer/fb_findfile.c
    branches/vince/netsurf-fb/framebuffer/fb_findfile.h
Modified:
    branches/vince/netsurf-fb/Makefile
    branches/vince/netsurf-fb/Makefile.config
    branches/vince/netsurf-fb/Makefile.sources
    branches/vince/netsurf-fb/framebuffer/fb_frontend_ablefb.c
    branches/vince/netsurf-fb/framebuffer/fb_frontend_linuxfb.c
    branches/vince/netsurf-fb/framebuffer/fb_gui.c

Modified: branches/vince/netsurf-fb/Makefile
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/Makefile?rev=5416&r1=5415&r2=5416&view=diff
==============================================================================
--- branches/vince/netsurf-fb/Makefile (original)
+++ branches/vince/netsurf-fb/Makefile Tue Sep 23 06:05:00 2008
@@ -455,6 +455,9 @@
   NETSURF_FEATURE_BMP_CFLAGS := -DWITH_BMP
   NETSURF_FEATURE_GIF_CFLAGS := -DWITH_GIF
 
+  CFLAGS += '-DNETSURF_FB_RESPATH="$(NETSURF_FB_RESPATH_$(NETSURF_FB_FRONTEND))"'
+  CFLAGS += '-DNETSURF_FB_HOMEPATH="$(NETSURF_FB_HOMEPATH_$(NETSURF_FB_FRONTEND))"'
+
   ifeq ($(NETSURF_FB_FRONTEND),linux)
     $(eval $(call pkg_config_find_and_add,RSVG,librsvg-2.0,SVG rendering))
     $(eval $(call pkg_config_find_and_add,ROSPRITE,librosprite,RISC OS sprite rendering))
@@ -481,6 +484,7 @@
     LDFLAGS += -lxml2 -lz -ljpeg -lcurl -lm 
     SUBTARGET := -able
   endif
+
   ifeq ($(NETSURF_FB_FRONTEND),dummy)
     $(eval $(call pkg_config_find_and_add,RSVG,librsvg-2.0,SVG rendering))
     $(eval $(call pkg_config_find_and_add,ROSPRITE,librosprite,RISC OS sprite rendering))

Modified: branches/vince/netsurf-fb/Makefile.config
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/Makefile.config?rev=5416&r1=5415&r2=5416&view=diff
==============================================================================
--- branches/vince/netsurf-fb/Makefile.config (original)
+++ branches/vince/netsurf-fb/Makefile.config Tue Sep 23 06:05:00 2008
@@ -197,6 +197,16 @@
   # Valid options: YES, NO
   NETSURF_USE_HARU_PDF := NO
 
+  # Framebuffer frontends may have differing root paths for resources
+  # As such, these specify the resource path and config path.
+  NETSURF_FB_RESPATH_linux := /usr/share/netsurf/
+  NETSURF_FB_RESPATH_able := (tftpboot)/
+  NETSURF_FB_RESPATH_dummy := ./
+
+  NETSURF_FB_HOMEPATH_linux := ~/.netsurf/
+  NETSURF_FB_HOMEPATH_able := (tftpboot)/
+  NETSURF_FB_HOMEPATH_dummy := ./
+
 endif
 
 # Include any local overrides

Modified: branches/vince/netsurf-fb/Makefile.sources
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/Makefile.sources?rev=5416&r1=5415&r2=5416&view=diff
==============================================================================
--- branches/vince/netsurf-fb/Makefile.sources (original)
+++ branches/vince/netsurf-fb/Makefile.sources Tue Sep 23 06:05:00 2008
@@ -95,7 +95,8 @@
 S_FRAMEBUFFER := fb_gui.c tree.c history.c hotlist.c fb_schedule.c	\
 	thumbnail.c misc.c fb_bitmap.c fb_font.c font_8x16.c		\
 	fb_filetype.c login.c fb_cursor.c fb_plotters.c			\
-	fb_8bpp_plotters.c fb_16bpp_plotters.c fb_32bpp_plotters.c
+	fb_8bpp_plotters.c fb_16bpp_plotters.c fb_32bpp_plotters.c \
+	fb_findfile.c
 #	fb_1bpp_plotters.c
 
 ifeq ($(NETSURF_FB_FRONTEND),linux)

Added: branches/vince/netsurf-fb/framebuffer/fb_findfile.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_findfile.c?rev=5416&view=auto
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_findfile.c (added)
+++ branches/vince/netsurf-fb/framebuffer/fb_findfile.c Tue Sep 23 06:05:00 2008
@@ -1,0 +1,85 @@
+/*
+ * Copyright 2008 Daniel Silverstone <dsilvers at netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <limits.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "fb_findfile.h"
+
+static bool
+fb_findfile_exists(char *buffer, const char *base, const char *filename)
+{
+        if (base == NULL)
+                return false;
+        
+        if (*base == '~') {
+                snprintf(buffer, PATH_MAX, "%s/%s/%s", 
+                         getenv("HOME") ? getenv("HOME") : "",
+                         base + 1, filename);
+        } else {
+                snprintf(buffer, PATH_MAX, "%s/%s", base, filename);
+        }
+        
+        return (access(buffer, R_OK) == 0);
+}
+
+char *
+fb_findfile(const char *filename)
+{
+        static char buffer[PATH_MAX];
+
+        /* Search sequence is:
+         * home/filename
+         * res-env/filename
+         * resources/filename
+         */
+        
+        if (fb_findfile_exists(buffer, NETSURF_FB_HOMEPATH, filename))
+                return buffer;
+        if (fb_findfile_exists(buffer, getenv("NETSURF_RES"), filename))
+                return buffer;
+        if (fb_findfile_exists(buffer, NETSURF_FB_RESPATH, filename))
+                return buffer;
+        
+        return NULL;
+}
+
+char *
+fb_findfile_asurl(const char *filename)
+{
+        static char buffer[PATH_MAX];
+        char *f = fb_findfile(filename);
+        
+        if (f == NULL)
+                return NULL;
+        
+        snprintf(buffer, PATH_MAX, "file://%s", f);
+        
+        return strdup(buffer);
+}
+
+/*
+ * Local Variables:
+ * c-basic-offset: 8
+ * End:
+ */
+

Added: branches/vince/netsurf-fb/framebuffer/fb_findfile.h
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_findfile.h?rev=5416&view=auto
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_findfile.h (added)
+++ branches/vince/netsurf-fb/framebuffer/fb_findfile.h Tue Sep 23 06:05:00 2008
@@ -1,0 +1,25 @@
+/*
+ * Copyright 2008 Daniel Silverstone <dsilvers at netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NETSURF_FB_FINDFILE_H
+#define NETSURF_FB_FINDFILE_H
+
+extern char *fb_findfile(const char *filename);
+extern char *fb_findfile_asurl(const char *filename);
+
+#endif /* NETSURF_FB_FINDFILE_H */

Modified: branches/vince/netsurf-fb/framebuffer/fb_frontend_ablefb.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_frontend_ablefb.c?rev=5416&r1=5415&r2=5416&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_frontend_ablefb.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_frontend_ablefb.c Tue Sep 23 06:05:00 2008
@@ -91,21 +91,9 @@
         /* set stdin to nonblocking */
         fcntl(0, F_SETFL, O_NONBLOCK);
 
-//#define FILE_PFX "(cd0)/res/"
-#define FILE_PFX "(tftpboot)/"
-
-        /* load browser messages */
-        messages_load(FILE_PFX "messages");
-
-        /* load browser options */        
-	options_read(FILE_PFX "Options");
-
         /* override some options */
         option_max_cached_fetch_handles = 1;
         option_max_fetchers = option_max_fetchers_per_host = 1;
-
-        default_stylesheet_url = strdup("file://" FILE_PFX "default.css");
-        //default_stylesheet_url = strdup("http://jennifer.kyllikki.org/~vince/res/default.css");
 
         return newfb;
 }

Modified: branches/vince/netsurf-fb/framebuffer/fb_frontend_linuxfb.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_frontend_linuxfb.c?rev=5416&r1=5415&r2=5416&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_frontend_linuxfb.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_frontend_linuxfb.c Tue Sep 23 06:05:00 2008
@@ -541,20 +541,11 @@
         if (keyboardfd < 0) {
                 fprintf(stderr, "Unable to open /dev/input/event0 no keyboard\n");                
         } 
+        
         mousefd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK);
         if (mousefd < 0) {
                 fprintf(stderr, "Unable to open /dev/input/event2 no mouse\n");                
         } 
-
-#define FILE_PFX "/home/vince/netsurf/netsurf-fb/framebuffer/res/"
-
-        /* load browser messages */
-        messages_load(FILE_PFX "messages");
-
-        /* load browser options */        
-	options_read(FILE_PFX "Options");
-
-        default_stylesheet_url = strdup("file://"FILE_PFX"/default.css");
 
         return newfb;
 }

Modified: branches/vince/netsurf-fb/framebuffer/fb_gui.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_gui.c?rev=5416&r1=5415&r2=5416&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_gui.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_gui.c Tue Sep 23 06:05:00 2008
@@ -34,6 +34,8 @@
 #include "framebuffer/fb_plotters.h"
 #include "framebuffer/fb_schedule.h"
 #include "framebuffer/fb_cursor.h"
+#include "framebuffer/fb_findfile.h"
+
 #include "content/urldb.h"
 #include "desktop/history_core.h"
 #include "content/fetch.h"
@@ -136,6 +138,14 @@
         LOG(("argc %d, argv %p", argc, argv));
 
         framebuffer = fb_os_init(argc, argv);
+        
+        /* load browser messages */
+        messages_load(fb_findfile("messages"));
+
+        /* load browser options */        
+	options_read(fb_findfile("Options"));
+
+        default_stylesheet_url = fb_findfile_asurl("default.css");
 
         switch (framebuffer->bpp) {
                 /*        case 1:




More information about the netsurf-commits mailing list