On Mon, 2009-03-30 at 12:36 +0200, netsurf.list.markie1(a)dfgh.net wrote:
So I've tracked down more applications of the 256-byte Url
limit,
putting them all together in a function looks a good idea, that could
then be modified to cope with RISC as appropriate
In general, this looks ok. Please ensure lines are wrapped to 80
columns, using 2 tabs for indenting continuation lines.
Index: desktop/browser.c
===================================================================
--- desktop/browser.c (revision 6935)
+++ desktop/browser.c (working copy)
@@ -1092,6 +1079,27 @@
browser_window_set_scale_internal(&bw->iframes[i],
scale);
}
+void browser_window_refresh_url_bar(struct browser_window *bw, char
*url, char *frag)
+{
url and frag should be const char *.
+ int l = strlen(url);
+ l += (frag) ? strlen(frag) : 0;
+ char *url_buf = (char *)malloc((l + 2) * (sizeof (char)));
url_buf will need to be declared before the l += line, else you'll break
the BeOS build. (Despite what any documentation says, the core must be
C89 these days.)
sizeof(char) is defined to be 1, so you can remove the * (sizeof(char)).
The cast of the result of malloc is unnecessary -- void * is implicitly
cast to the lvalue's type.
+ if (url_buf) {
+ if (frag) {
+ snprintf(url_buf, l, "%s#%s",
+ url, frag);
l + 1, surely?
+ *(url_buf + l + 1) = 0;
'\0' is clearer.
+ } else {
+ snprintf(url_buf, l, "%s",
+ url);
+ *(url_buf + l) = 0;
+ }
+ gui_window_set_url(bw->window, url_buf);
+ free(url_buf);
+ } else {
+ warn_user("NoMemory", 0);
+ }
+}
/**
* Locate a browser window in the specified stack according.
Index: desktop/browser.h
===================================================================
--- desktop/browser.h (revision 6935)
+++ desktop/browser.h (working copy)
@@ -231,6 +231,8 @@
void browser_window_reformat(struct browser_window *bw, int width,
int height);
void browser_window_set_scale(struct browser_window *bw, float scale,
bool all);
+void browser_window_refresh_url_bar(struct browser_window *bw, char *
url, char * frag);
+
Similarly, constify.
J.