On Sat, Jan 14, 2012 at 07:50:51PM -0500, Thomas Dickey wrote:
> On Sun, Jan 15, 2012 at 12:36:36AM +0000, Mark Skilbeck wrote:
> > Okay. So with a little effort, I wrote a basic patch. See the attached. I 
> > went 
> > with the "search for %s -> prompt for query" approach. Of course, the code 
> > is
> > bad - I'm not a great or even good coder, but it should serve as an outline 
> > that
> > you could give me feedback on.
> 
> thanks - I'll pick it apart.
> 
> -- 
> Thomas E. Dickey <[email protected]>
> http://invisible-island.net
> ftp://invisible-island.net

Attached is a revised patch. This one *doesn't* die because of uninitialized 
memory ;)

I haven't figured out how to clear the old query from the status line, though.

- mgsk.
--- src/LYMainLoop.c	2011-06-13 01:18:54.000000000 +0100
+++ /home/mark/src/lynx2-8-8/src/LYMainLoop.c	2012-01-15 16:27:28.112808773 +0000
@@ -3400,6 +3400,45 @@
 }
 #endif
 
+static const char *hexy = "0123456789ABCDEF";
+#define HEX(n) hexy[n]
+static char *urlencode(char *str)
+{
+     // use 3x size of str, assuming every character of str needs to be encoded
+     // need 3 characters to encode each.
+     char *encoded = malloc(strlen(str) * 3 + 1),
+	  *ptr = encoded;
+
+     assert(encoded);
+     
+     while (*str)
+     {
+	  if (*str == ' ')
+	  {
+	       *encoded = '+';
+	       encoded++;
+	  }
+	  else if ((*str != '.' && *str != '-' && *str != '~' && *str != '_')
+		   &&
+		   (*str < 57 || (*str > 65 && *str < 97) || *str > 122))
+	  {
+	       *encoded++ = '%';
+	       *encoded++ = HEX((*str >> 4));
+	       *encoded++ = HEX((*str & 0xF));
+	  }
+	  else
+	  {
+	       *encoded++ = *str;
+	  }
+
+	  str++;
+     }
+
+     *encoded = '\0';
+
+     return ptr;
+}
+
 static BOOLEAN handle_LYK_JUMP(int c,
 			       char *user_input_buffer,
 			       char **old_user_input GCC_UNUSED,
@@ -3446,11 +3485,40 @@
 		FREE(ret);
 		return TRUE;
 	    }
-#endif /* PERMIT_GOTO_FROM_JUMP */
+#endif /* PERMIT_GOTO_FROM_JUMP */	    
 	    ret = HTParse(ret, startfile, PARSE_ALL);
 	    if (!LYTrimStartfile(ret)) {
 		LYRemoveBlanks(user_input_buffer);
 	    }
+	    if (strstr(ret, "%s")) {
+		 int query_len = 0;
+		 char input[100];
+		 RecallType recall = NORECALL;
+
+		 statusline("Query: ");
+		 if (LYGetStr(input, VISIBLE, 100, recall) < 0) {
+		      /*
+		       * cancelled via ^G
+		       */
+		      HTInfoMsg(CANCELLED);
+		      return FALSE;
+		 }
+
+		 if (*input != '\0') {
+		      char *encoded = urlencode(input),
+			   *sub_ret = NULL;
+
+		      // -2, for %s replacement
+		      ret = realloc(ret, strlen(ret) + strlen(encoded) - 2);
+		      sub_ret = malloc(strlen(ret) + strlen(encoded) - 2);
+		      strncpy(sub_ret, ret, strlen(ret));
+		      sub_ret[strlen(ret)] = '\0';
+		      sprintf(ret, sub_ret, encoded);
+		 }
+		 else {
+		      HTInfoMsg(CANCELLED);
+		 }
+	    }
 	    set_address(&newdoc, ret);
 	    StrAllocCopy(lynxjumpfile, ret);
 	    LYFreePostData(&newdoc);
_______________________________________________
Lynx-dev mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lynx-dev

Reply via email to