Marcos Cruz <[email protected]> wrote:
> I think one optional parameter is enough in most cases; and it's
> easier to implement. 

The attached patch should do this. It makes the %s in search engine
definitions in the rc file optional. So you can now use zero or one
parameters. Intended behaviour:

- If parameter given, but none expected, ignore them and open the
  shortcut.
- If no parameter given, but one was expected, open the shortcut with
  blank string as parameter.

Testing highly appreciated!

Hannes
diff --git a/main.c b/main.c
index 40c6e8d..1559275 100644
--- a/main.c
+++ b/main.c
@@ -1208,7 +1208,7 @@ open_arg(const Arg *arg) {
     char *argv[64];
     char *s = arg->s, *p = NULL, *new;
     Arg a = { .i = NavigationReload };
-    int len;
+    int len, space = 0;
     char *search_uri, *search_term;
     struct stat statbuf;
 
@@ -1242,16 +1242,31 @@ open_arg(const Arg *arg) {
             return TRUE;        
         /* check for search engines */
         p = strchr(s, ' ');
-        if (p) {                                                         /* check for search engines */
+        if (!p) {
+            /* shortcut without search term */
+            p = s;
+        } else {
+            /* search term given */
             *p = '\0';
-            search_uri = find_uri_for_searchengine(s);
-            if (search_uri != NULL) {
+            space = 1;
+        }
+        search_uri = find_uri_for_searchengine(s);
+        if (search_uri != NULL) {
+            if (space > 0) {
                 search_term = soup_uri_encode(p+1, "&");
                 new = g_strdup_printf(search_uri, search_term);
                 g_free(search_term);
+            } else {
+                if (!strstr(search_uri, "%s"))
+                    new = g_strdup_printf(search_uri);
+                else {
+                    /* the search engine definition expected an argument */
+                    new = g_strdup_printf(search_uri, "");
+                }
             }
-            *p = ' ';
         }
+        if (space > 0)
+            *p = ' ';
         if (!new) {
             if (len > 3 && strstr(s, "://")) {                      /* valid url? */
                 p = new = g_malloc(len + 1);
@@ -1272,7 +1287,7 @@ open_arg(const Arg *arg) {
                     new = g_malloc(sizeof("file://") + len);
                     sprintf(new, "file://%s", s);
                 }
-            } else if (p || !strchr(s, '.')) {                      /* whitespaces or no dot? */
+            } else if (space > 0 || !strchr(s, '.')) {                      /* whitespaces or no dot? */
                 search_uri = find_uri_for_searchengine(defaultsearch);
                 if (search_uri != NULL) {
                     search_term = soup_uri_encode(s, "&");
diff --git a/utilities.c b/utilities.c
index 8037c52..df04c48 100644
--- a/utilities.c
+++ b/utilities.c
@@ -702,7 +702,7 @@ static gboolean sanity_check_search_url(const char *string)
         }
     }
 
-    return !was_percent_char && percent_s_count == 1;
+    return percent_s_count == 0 || percent_s_count == 1;
 }
 
 void make_searchengines_list(Searchengine *searchengines, int length)
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Vimprobable-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vimprobable-users

Reply via email to