Surfer html viewer, want to improve it

Under development: PCMCIA, wireless, etc.
Message
Author
User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

Surfer html viewer, want to improve it

#1 Post by BarryK »

Some pups, including Quirky, not sure about latest Xenialpup and Slacko, use 'surfer' for the internal html help viewer.

This is a very small web page browser, written in C and uses GTK and libgtkhtml.

It has a couple of dependencies from the same guy who created surfer, 'gnet' and 'libsystem', for pups that use surfer, these should already be in the devx.

All sources are here:
http://distro.ibiblio.org/quirky/quirky ... ml.tar.bz2
http://distro.ibiblio.org/quirky/quirky ... .8.tar.bz2
http://distro.ibiblio.org/quirky/quirky ... d1.tar.bz2

Compiling is simple Makefile, from memory, need to edit PREFIX, change from /usr/local to /usr

libgtkhtml is there also:
http://distro.ibiblio.org/quirky/quirky ... .1.tar.bz2

Surfer is a great little viewer for local html files, however, there is one big problem. libgtkhtml supports html4 and some css, no javascript.
If surfer is used to view a local help file, which has links to the internet, then surfer will attempt to open those links, and in many cases will crash.

What would be really great is to hack the C source of surfer somehow, so that two kinds of hyperlinks can be specified in a web page, local, suitable to be opened by surfer, and remote (the internet) and opened by 'defaultbrowser' (which will be SeaMonkey, Firefox, etc).

I have been staring at the source code, but can't see how to do it. So, thought that I would throw the problem out there, see if someone with gtk coding skills can think of how to do it. Or maybe not even gtk, just C skills.

There might not be any takers, but you never know...

Edit
Note, there is one little foible of surfer, it does not like "file://" prefix on local links. So open a file like this:
# surfer /usr/share/doc/home.htm
[url]https://bkhome.org/news/[/url]

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#2 Post by SFR »

Hey Barry, maybe something like this?

Code: Select all

diff -Naur Surfer-0.0.7-patched_libgtkhtml_old/src/ghtml-gtkhtml.c Surfer-0.0.7-patched_libgtkhtml_new/src/ghtml-gtkhtml.c
--- Surfer-0.0.7-patched_libgtkhtml_old/src/ghtml-gtkhtml.c	2009-08-14 18:54:05.000000000 +0200
+++ Surfer-0.0.7-patched_libgtkhtml_new/src/ghtml-gtkhtml.c	2017-08-01 00:59:41.118965319 +0200
@@ -1067,7 +1067,15 @@
 	fprintf(stderr, "DEBUG: %s(\"%s\") base=\"%s\" => \"%s\"\n", __func__,
 			url, _ghtml_get_base(ghtml), link);
 #endif
-	_ghtml_document_load(ghtml, link, NULL);
+	if (g_str_has_prefix(link, "http://")	||
+		g_str_has_prefix(link, "https://")	||
+		g_str_has_prefix(link, "ftp://"))	/* maybe more prefixes are needed */
+	{
+		system(g_strdup_printf("%s %s %s", "defaultbrowser", link, "&")); /* & to send it to background */
+	}
+	else
+		_ghtml_document_load(ghtml, link, NULL);
+
 	g_free(link);
 }
(Also attached, because copying from browser may append spaces to each line.)

I'm just a beginner in C and that's the best I could come up with, but works just fine down here.

Greetings!
Attachments
surfer-remote_links.patch.tar.gz
(543 Bytes) Downloaded 362 times
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#3 Post by disciple »

Using xdg-open is more portable - is it included in all puppies these days?
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#4 Post by BarryK »

SFR,
I tested your patch, it works great. I appreciate the help, it makes Surfer so much more useful.

I have applied SFR's patch and assigned it as HelpSurfer version 0.1, source here:
http://barryk.org/news/?viewDetailed=00632
[url]https://bkhome.org/news/[/url]

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#5 Post by SFR »

Alright, glad it works!

However, here's a small revision, because I just realized that URLs that contain an amphersand won't be working properly without quotes.
Also, replaced all calls to g_str_has_prefix with one g_regex_match_simple and since g_strdup_printf allocates memory, I had to use a transient variable to free it afterwards.

Code: Select all

diff -Naur Surfer-0.0.7-patched_libgtkhtml_old/src/ghtml-gtkhtml.c Surfer-0.0.7-patched_libgtkhtml_new/src/ghtml-gtkhtml.c
--- Surfer-0.0.7-patched_libgtkhtml_old/src/ghtml-gtkhtml.c	2009-08-14 18:54:05.000000000 +0200
+++ Surfer-0.0.7-patched_libgtkhtml_new/src/ghtml-gtkhtml.c	2017-08-01 11:17:41.846580886 +0200
@@ -1059,6 +1059,7 @@
 {
 	GHtml * ghtml;
 	gchar * link;
+	gchar * syscmd;
 
 	ghtml = g_object_get_data(G_OBJECT(document), "ghtml");
 	if((link = _ghtml_make_url(_ghtml_get_base(ghtml), url)) == NULL)
@@ -1067,7 +1068,14 @@
 	fprintf(stderr, "DEBUG: %s(\"%s\") base=\"%s\" => \"%s\"\n", __func__,
 			url, _ghtml_get_base(ghtml), link);
 #endif
-	_ghtml_document_load(ghtml, link, NULL);
+	if (g_regex_match_simple("^http://|^https://|^ftp://", link, 0, 0))
+	{
+		syscmd = g_strdup_printf("%s '%s' %s", "defaultbrowser", link, "&");
+		system(syscmd);
+		g_free(syscmd);
+	}
+	else
+		_ghtml_document_load(ghtml, link, NULL);
 	g_free(link);
 }
___________

@Disciple: yeah, xdg-open works, too (at least here in Fatdog).

Greetings!
Attachments
surfer-remote_links_v2.patch.tar.gz
(622 Bytes) Downloaded 333 times
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

#6 Post by gyro »

It might be a bit rude of me to comment since you already have a working patch;
But would it not be better to turn the test around:

Code: Select all

+   if (g_str_has_prefix(link, "file:///")
+      _ghtml_document_load(ghtml, link, NULL);
+   else
+   {
+      syscmd = g_strdup_printf("%s '%s' %s", "defaultbrowser", link, "&");
+      system(syscmd);
+      g_free(syscmd);
+   }
gyro

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#7 Post by SFR »

Not at all, better_code > one's_feelings. ;)

However, I ditched this approach at the very beginning, because of:
BarryK in the first post wrote:Note, there is one little foible of surfer, it does not like "file://" prefix on local links.
Local links in Fatdog docs (that I used for testing) don't contain this prefix and are relative:

Code: Select all

<a href="tray.html">Tray icons</a> 
so it wouldn't work anyway...

Btw, I think ^mailto: could also be added. Surfer does not even recognize this protocol.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#8 Post by BarryK »

SFR,
That's great, I will apply your latest patch.

While I am putting in requests :)

If you look at helpsurfer-0.1, src/Makefile has "-D NOURLBAR, because as a simple help viewer I didn't think it needed the url entry box.

Also there is "-D EMBEDDED", which removes the drop-down menu bar.

The icon bar still displays, but it would be nice with an "exit" icon. Currently, the only way to close the app is by the close-box top-right of window.
[url]https://bkhome.org/news/[/url]

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#9 Post by SFR »

Here you go:

Code: Select all

diff -Naur helpsurfer-0.1_old/src/callbacks.c helpsurfer-0.1_new/src/callbacks.c
--- helpsurfer-0.1_old/src/callbacks.c	2009-08-14 18:55:18.000000000 +0200
+++ helpsurfer-0.1_new/src/callbacks.c	2017-08-02 12:17:50.366562155 +0200
@@ -47,6 +47,12 @@
 	return FALSE;
 }
 
+/* quit button */
+void on_button_close(GtkWidget * widget, gpointer data)
+{
+	on_closex(widget, NULL, data);
+}
+
 
 #ifndef EMBEDDED
 /* file menu */
diff -Naur helpsurfer-0.1_old/src/callbacks.h helpsurfer-0.1_new/src/callbacks.h
--- helpsurfer-0.1_old/src/callbacks.h	2009-08-14 18:55:18.000000000 +0200
+++ helpsurfer-0.1_new/src/callbacks.h	2017-08-02 12:17:27.103229126 +0200
@@ -24,6 +24,8 @@
 /* window */
 gboolean on_closex(GtkWidget * widget, GdkEvent * event, gpointer data);
 
+void on_button_close(GtkWidget * widget, gpointer data);
+
 #ifndef EMBEDDED
 /* file menu */
 void on_file_close(GtkWidget * widget, gpointer data);
diff -Naur helpsurfer-0.1_old/src/surfer.c helpsurfer-0.1_new/src/surfer.c
--- helpsurfer-0.1_old/src/surfer.c	2017-08-01 09:10:39.000000000 +0200
+++ helpsurfer-0.1_new/src/surfer.c	2017-08-02 12:18:58.289894600 +0200
@@ -205,6 +205,9 @@
 	g_signal_connect(G_OBJECT(toolitem), "toggled", G_CALLBACK(
 				on_fullscreen), surfer);
 	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1);
+	toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_QUIT);
+	g_signal_connect(G_OBJECT(toolitem), "clicked", G_CALLBACK(on_button_close), surfer);
+	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1);
 	gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
 	/* toolbar */
 //#ifndef NOURLBAR
Just note that this patch is against helpsurfer-0.1.

Greetings!
Attachments
helpsurfer-quit_button.patch.tar.gz
(729 Bytes) Downloaded 322 times
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#10 Post by BarryK »

That's great!

I have bumped HelpSurfer to version 0.2, see blog post:

http://barryk.org/news/?viewDetailed=00635
[url]https://bkhome.org/news/[/url]

User avatar
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

#11 Post by mavrothal »

ignor... :oops:
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#12 Post by BarryK »

Have now bumped HelpSurfer to version 0.3.

Source:
http://distro.ibiblio.org/quirky/quirky ... 0.3.tar.gz

PET:
http://distro.ibiblio.org/quirky/quirky ... erus64.pet

There was something else that I wanted HelpSurfer to be able to do: execute local executables.
This is not a web browser, it is a local help viewer, and although it is not legitimate html, HelpSurfer now supports hyperlinks to

"exec:<executable> <parameters>"

For example:

Code: Select all

<a href="exec:leafpad /usr/share/doc/home.htm">EXECUTE LEAFPAD</a>
I have a requirement for this feature.

Patch for 0.2 is attached, with a false ".gz" appended.

Thanks to SFR, 'coz I was able to easily see how to extend what he has already done.
Attachments
helpsurfer-link-executable.patch.gz
(845 Bytes) Downloaded 345 times
[url]https://bkhome.org/news/[/url]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#13 Post by technosaurus »

I love to see people working on projects like this, but netsurf-framebuffer or even the gtk version is better and smaller... and still actively developed.
The big advantage to the framebuffer version though is that puppy's man pages work in the console. I put together a patch a while back that automatically detected linux framebuffer vs X11(actually xcb) backends... it even works in wayland and any platform with SDL support. Not mention that netsurf now uses duktape for JavaScript support.

If you want something really lite, check out goingnuts Chimera patches.

Regarding the exec "feature", this can be done more securely using cgi scripts on localhost like slitaz does for a lot of their apps (things we typically use gtkdialog for)

#EDIT: added links
Last edited by technosaurus on Tue 08 Aug 2017, 19:51, edited 1 time in total.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#14 Post by don570 »

I don't know how to program but I did make the following observation...

If error messages are removed then more downloaded web pages will open up correctly. For example downloaded murga forum web pages
open nicely (except for images) and plain text files and XML.

What I did was simplify following

Code: Select all

/* surfer_error */
int surfer_error(Surfer * surfer, char const * message, int ret)
{
	GtkWidget * dialog;

	dialog = gtk_message_dialog_new((surfer != NULL)
			? GTK_WINDOW(surfer->window) : NULL,
			GTK_DIALOG_DESTROY_WITH_PARENT,
			GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", message);
	gtk_window_set_title(GTK_WINDOW(dialog), "Error");
	g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(
				gtk_widget_destroy), NULL);
	gtk_widget_show(dialog);
	return ret;
}
to

Code: Select all

/* surfer_error */
int surfer_error(Surfer * surfer, char const * message, int ret)
{
	
	return ret;
}

This gets rid of error message, however I must run 'killall surfer'
in terminal to stop memory filling up when a incompatible page is loaded.

__________________________________________________

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#15 Post by BarryK »

A quick post: yesterday I bumped the version to 0.5.

Source:
http://distro.ibiblio.org/quirky/quirky ... 0.5.tar.gz

Blog post:
http://barryk.org/news/?viewDetailed=00641


don570,
I will take a look at your suggestion.
[url]https://bkhome.org/news/[/url]

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#16 Post by don570 »

I also noticed another strange behaviour.
When surfer opens the text file
/usr/share/doc/align.txt
only one line is shown whereas seamonkey will show entire file.

-----------------------------------------------------------------

Perhaps helpsurfer could become the default htmlviewer
by first checking if the word 'javascript' appears in the first 20 lines of the file.

If it does contain javascript ---> Then quit or use 'defaultbrowser'.

I attached the file that I use to check for javascript....
____________________________________________________

Reading about javascript
https://www.w3schools.com/js/js_whereto.asp

That is old fashioned method to add javascript to html

Perhaps checking for script tag would be necessary ---> </script>

______________________________________________
Attachments
H_R_McMaster_Facts_McMaster_Leaks.zip
File to test surfer for javascript
(26.38 KiB) Downloaded 254 times

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#17 Post by BarryK »

technosaurus wrote:I love to see people working on projects like this, but netsurf-framebuffer or even the gtk version is better and smaller... and still actively developed.
The big advantage to the framebuffer version though is that puppy's man pages work in the console. I put together a patch a while back that automatically detected linux framebuffer vs X11(actually xcb) backends... it even works in wayland and any platform with SDL support. Not mention that netsurf now uses duktape for JavaScript support.

If you want something really lite, check out goingnuts Chimera patches.

Regarding the exec "feature", this can be done more securely using cgi scripts on localhost like slitaz does for a lot of their apps (things we typically use gtkdialog for)

#EDIT: added links
I am becoming very frustrated with Surfer! It is too unstable.

So, will have a look at Netsurf next.
[url]https://bkhome.org/news/[/url]

Sailor Enceladus
Posts: 1543
Joined: Mon 22 Feb 2016, 19:43

#18 Post by Sailor Enceladus »

BarryK wrote:I am becoming very frustrated with Surfer! It is too unstable.

So, will have a look at Netsurf next.
fwiw netsurf crashed on me when visiting github puppylinux in devuan ascii

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#19 Post by BarryK »

Sailor Enceladus wrote:
BarryK wrote:I am becoming very frustrated with Surfer! It is too unstable.

So, will have a look at Netsurf next.
fwiw netsurf crashed on me when visiting github puppylinux in devuan ascii
I have just compiled netsurf 3.6, in Easy 0.3.1 pre-alpha (based on Ubuntu 16.04.3 debs). Woof-CE github,

https://github.com/puppylinux-woof-CE/woof-CE

Doesn't crash, but it doesn't render properly. I have got javascript enabled.


As a local html help viewer though, netsurf is brilliant, coz it is so fast.
[url]https://bkhome.org/news/[/url]

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#20 Post by BarryK »

technosaurus wrote:Regarding the exec "feature", this can be done more securely using cgi scripts on localhost like slitaz does for a lot of their apps (things we typically use gtkdialog for)
Yeah, but there is no way of doing it without running a local web server, is there?

Maybe it is possible to define a custom url protocol, did see something about that for firefox.
[url]https://bkhome.org/news/[/url]

Post Reply