gboolean vb_load_uri(const Arg *arg)
{
- char *uri, *rp, *path = arg->s;
+ char *uri = NULL, *rp, *path = arg->s;
struct stat st;
if (!path) {
path = vb.config.home_page;
}
- /* check if the path is a file path */
- if (stat(path, &st) == 0) {
+ if (g_strrstr(path, "://")) {
+ uri = g_strdup(path);
+ } else if (stat(path, &st) == 0) {
+ /* check if the path is a file path */
rp = realpath(path, NULL);
uri = g_strdup_printf("file://%s", rp);
free(rp);
- } else if (!strchr(path, '.' && !strchr(path, '/'))) {
- char *part = NULL, *tmpl = NULL, *query = NULL;
-
- /* look up for a searchengine with handle */
- if ((part = strchr(path, ' '))) {
- *part = '\0';
- tmpl = searchengine_get_uri(path);
- query = soup_uri_encode(part + 1, "&");
- } else {
- tmpl = searchengine_get_uri(NULL);
- query = soup_uri_encode(path, "&");
- }
+ } else if (!strchr(path, '.')) {
+ /* use a searchengine */
+ uri = searchengine_get_uri(path);
+ }
- if (tmpl) {
- uri = g_strdup_printf(tmpl, query);
- } else {
- uri = g_strrstr(path, "://") ? g_strdup(path) : g_strdup_printf("http://%s", path);
- }
- g_free(query);
- } else {
- uri = g_strrstr(path, "://") ? g_strdup(path) : g_strdup_printf("http://%s", path);
+ if (!uri) {
+ uri = g_strdup_printf("http://%s", path);
}
/* change state to normal mode */
char *path = util_get_config_dir();
if (vb.custom_config) {
- char *rp = realpath(vb.custom_config, NULL);
+ char *rp = realpath(vb.custom_config, NULL);
vb.files[FILES_CONFIG] = g_strdup(rp);
free(rp);
} else {
return TRUE;
}
-char *searchengine_get_uri(const char *handle)
+/**
+ * Retrieves the search uri for given query string.
+ * Not that the memory of the returned uri must be freed.
+ */
+char *searchengine_get_uri(const char *string)
{
- const char *def = vb.behave.searchengine_default;
GSList *l = NULL;
+ char *p = NULL, *tmpl = NULL, *query = NULL, *uri = NULL;
+
+ if ((p = strchr(string, ' '))) {
+ *p = '\0';
+ /* is the first word the handle? */
+ if ((l = searchengine_find(string))) {
+ tmpl = ((Searchengine*)l->data)->uri;
+ query = soup_uri_encode(p + 1, "&");
+ } else {
+ *p = ' ';
+ }
+ }
+
+ if (!tmpl && (l = searchengine_find(vb.behave.searchengine_default))) {
+ tmpl = ((Searchengine*)l->data)->uri;
+ query = soup_uri_encode(string, "&");
+ }
+
+ if (tmpl) {
+ uri = g_strdup_printf(tmpl, query);
+ g_free(query);
- if (handle && (l = searchengine_find(handle))) {
- return ((Searchengine*)l->data)->uri;
- } else if (def && (l = searchengine_find(def))) {
- return ((Searchengine*)l->data)->uri;
+ return uri;
}
return NULL;