diff src/misc.c @ 2146:aac29835ca8c

Added an optional label to dillorc's search_url. Format: "[<label> ]<url>"
author Jorge Arellano Cid <jcid@dillo.org>
date Sun, 24 Jul 2011 13:47:25 -0400
parents e44231f9c6ca
children
line wrap: on
line diff
--- a/src/misc.c	Sun Jul 24 13:47:24 2011 -0400
+++ b/src/misc.c	Sun Jul 24 13:47:25 2011 -0400
@@ -383,6 +383,38 @@
 }
 
 /*
+ * Parse dillorc's search_url string ("[<label> ]<url>")
+ * Return value: -1 on error, 0 on success (and label and urlstr pointers)
+ */
+int a_Misc_parse_search_url(char *source, char **label, char **urlstr)
+{
+   static char buf[32];
+   char *p, *q;
+   int ret = -1;
+
+   if ((p = strrchr(source, ' '))) {
+      /* label and url pair */
+      strncpy(buf,source,MIN(p-source,31));
+      buf[MIN(p-source,31)] = 0;
+      source = p+1;
+      if ((p = strchr(source, '/')) && p[1] && (q = strchr(p+2,'/'))) {
+         *urlstr = source;
+         ret = 0;
+      }
+   } else {
+      /* url only, make a custom label */
+      if ((p = strchr(source, '/')) && p[1] && (q = strchr(p+2,'/'))) {
+         strncpy(buf,p+2,MIN(q-p-2,31));
+         buf[MIN(q-p-2,31)] = 0;
+         *urlstr = source;
+         ret = 0;
+      }
+   }
+   *label = buf;
+   return ret;
+}
+
+/*
  * Encodes string using base64 encoding.
  * Return value: new string or NULL if input string is empty.
  */