You could look at urlencode() from php, should be fairly small and easy enough to rip.

---

static unsigned char hexchars[] = "0123456789ABCDEF";

/* {{{ php_url_encode
 */
PHPAPI char *php_url_encode(char *s, int len, int *new_length)
{
    register int x, y;
    unsigned char *str;

    str = (unsigned char *) emalloc(3 * len + 1);
    for (x = 0, y = 0; len--; x++, y++) {
        str[y] = (unsigned char) s[x];
        if (str[y] == ' ') {
            str[y] = '+';
#ifndef CHARSET_EBCDIC
        } else if ((str[y] < '0' && str[y] != '-' && str[y] != '.') ||
                   (str[y] < 'A' && str[y] > '9') ||
                   (str[y] > 'Z' && str[y] < 'a' && str[y] != '_') ||
                   (str[y] > 'z')) {
            str[y++] = '%';
            str[y++] = hexchars[(unsigned char) s[x] >> 4];
            str[y] = hexchars[(unsigned char) s[x] & 15];
        }
#else /*CHARSET_EBCDIC*/
        } else if (!isalnum(str[y]) && strchr("_-.", str[y]) == NULL) {
            /* Allow only alphanumeric chars and '_', '-', '.'; escape the rest 
*/
            str[y++] = '%';
            str[y++] = hexchars[os_toascii[(unsigned char) s[x]] >> 4];
            str[y] = hexchars[os_toascii[(unsigned char) s[x]] & 0x0F];
        }
#endif /*CHARSET_EBCDIC*/
    }
    str[y] = '\0';
    if (new_length) {
        *new_length = y;
    }
    return ((char *) str);
}
/* }}} */

On Friday, June 07, 2002 at 12:31PM, Scott Furt wrote:
>Derek Cunningham wrote:
>>On Thu, Jun06,02 12:53, Mr.X wrote:
>>>
>>>This is cool.  Works fine for me, by the way.
>>
>>
>>Hmm... now we need bbgoogle. :)
>>
>>DC
>>
>
>remove the space when strncat()'ing browser
>to real_command, build it.  (the patch shows the lines)
>
>modify bbweb.browser to be something like
>/usr/bin/mozilla http://www.google.com/search\?hl=en\&q=
>
>i have no idea how URL-escape stuff in C, so some queries
>might fail (ones with spaces or other funky chars), but
>that's the general idea of making bbweb into bbgoogle :-)
>
>maybe i'll use this opportunity to teach myself Perl/Tk
>or PHP-Gtk -- becuase then i could do so much more
>with it.

>--- bbweb.orig Fri Jun  7 12:19:33 2002
>+++ bbweb.c    Fri Jun  7 12:27:34 2002
>@@ -92,7 +92,7 @@
>       read_browser();
>       
>       strncat(real_command, browser, 100);
>-      strncat(real_command, " ", 2);
>+      //strncat(real_command, " ", 2);
> 
> 
>       for (i = 1; i < argc; i++)

Reply via email to