[Surfraw-devel] Google countries patch, Sun Java docs elvis

James TD Smith ahktenzero at dsl.pipex.com
Sun Mar 16 17:11:31 UTC 2008


I have patched the google elvis to support setting which country-specific Google
site to use. This also respects SURFRAW_lang. 

Also I have written an elvi to search Sun's Java API docs.

Both are attatched

--
James
-------------- next part --------------
--- surfraw-2.1.7.orig/elvi/google	2008-03-16 16:49:55.000000000 +0000
+++ surfraw-2.1.7/elvi/google	2008-03-16 17:00:48.000000000 +0000
@@ -4,9 +4,10 @@
 . surfraw || exit 1
 
 w3_config_hook () {
-def   SURFRAW_google_results $SURFRAW_results
-def   SURFRAW_google_search search
-defyn SURFRAW_google_lucky 0
+    def   SURFRAW_google_results $SURFRAW_results
+    def   SURFRAW_google_search search
+    defyn SURFRAW_google_lucky 0
+    def   SURFRAW_google_country us
 }
 
 w3_usage_hook () {
@@ -23,8 +24,13 @@
           bsd           |       BSD
           linux         |       Linux
           mac           |       Apple Macintosh
-          unclesam              U.S. Government
+          unclesam      |       U.S. Government
+	  images	|	Images
                                 Environment: SURFRAW_google_search
+  -country=			Select regional google site
+				Default is us (google.com)
+	   <ISO 3166 alpha-2 code>
+				Environment: SURFRAW_google_country 
 EOF
     w3_global_usage
 }
@@ -36,7 +42,8 @@
     -results=*) setopt   SURFRAW_google_results $optarg ;;
     -search=*)  setopt   SURFRAW_google_search  $optarg ;;
     -l*)        setoptyn SURFRAW_google_lucky   1       ;;
-	*) return 1 ;;
+    -country=*) setopt	 SURFRAW_google_country $optarg ;;
+    *) return 1 ;;
     esac
     return 0
 }
@@ -44,14 +51,27 @@
 w3_config
 w3_parse_args "$@"
 # w3_args now contains a list of arguments
+
+# Use SURFRAW_lang if present and the country has not been changed
+if test -n "$SURFRAW_lang" -a "$SURFRAW_google_country" == "us"; then
+    SURFRAW_google_country=$SURFRAW_lang;
+fi
+
+case "$SURFRAW_google_country" in
+  af|ag|ai|ar|au|bd|bn|bo|br|bs|bw|by|bz|co|cu|do|ec|eg|et|fj|gi|gt|hk|jm|ly|mt|mx|my|na|nf|ng|ni|np|nz|om|pa|pe|ph|pk|pr|py|qa|sa|sb|sg|sv|tj|tr|tw|ua|ug|uy|vn) domain=".co.${SURFRAW_google_country}" ;;
+  cr|id|il|in|jp|ke|kh|kr|ls|ma|th|uk|uz|vc|ve|vg|vi|ck|yu|za|zm|zw) domain="co.${SURFRAW_google_country}" ;;
+  us) domain="com";;
+  *)  domain=$SURFRAW_google_country ;;
+esac
+
 if test -z "$w3_args"; then
-    w3_browse_url "http://www.google.com/"
+    w3_browse_url "http://www.google.${domain}/"
 else
     escaped_args=`w3_url_of_arg $w3_args`
 	if [ $SURFRAW_google_lucky = 1 ]; then
 		button=`w3_url_escape "I'm Feeling Lucky"`
-		w3_browse_url "http://www.google.com/${SURFRAW_google_search}?q=${escaped_args}&btnI=$button&num=${SURFRAW_google_results}"	
+		w3_browse_url "http://www.google.${domain}/${SURFRAW_google_search}?q=${escaped_args}&btnI=$button&num=${SURFRAW_google_results}"	
 	else
-		w3_browse_url "http://www.google.com/${SURFRAW_google_search}?q=${escaped_args}&num=${SURFRAW_google_results}"
+		w3_browse_url "http://www.google.${domain}/${SURFRAW_google_search}?q=${escaped_args}&num=${SURFRAW_google_results}"
 	fi
 fi
-------------- next part --------------
#!/bin/sh
# $Id: $
# elvis: javasun	-- Search Java API docs (java.sun.com)
. surfraw || exit 1

w3_config_hook () {
    def SURFRAW_java_product se
    def SURFRAW_java_version 6
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
  Search Sun Java API docs (java.sun.com)
Local options:
  -v 				Java API version (1.2, 1.3, 1.4, 5, 6)
  -p 				Java product (se, ee, me)
EOF

    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
    -v*) setopt SURFRAW_java_version $optarg ;;
    -p*) setopt SURFRAW_java_product $optarg ;;
     *) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"

case "$SURFRAW_java_product" in
    [sS][eE])
	case "$SURFRAW_java_version" in
	    6) JAVA_SITE="javase/6/docs/api" ;;
	    5) JAVA_SITE="j2se/1.5.0/docs/api" ;;
	    1.4) JAVA_SITE="j2se/1.4.2/docs/api" ;;
	    1.3) JAVA_SITE="j2se/1.3/docs/api" ;;
	    *)
		echo "Docs for J2SE $SURFRAW_java_version are not available"
		exit 1 ;;
	esac ;;
	
    [eE][eE])
	case "$SURFRAW_java_version" in
	    6|5) JAVA_SITE="javaee/5/docs/api" ;;
	    1.4) JAVA_SITE="j2ee/1.4/docs/api" ;;
	    1.3) JAVA_SITE="j2ee/sdk_1.3/techdocs/api" ;;
	    1.2) JAVA_SITE="j2ee/sdk_1.2.1/techdocs/api" ;;
	    *) echo "Docs for J2EE $SURFRAW_java_version are not available"
	esac ;;

    [mM][eE])
	JAVA_SITE="j2me/docs" ;;
    *)
	echo "$SURFRAW_java_product is not a valid Java product"
	exit 1 ;;
esac

if test -z "$w3_args"; then
    w3_browse_url "http://java.sun.com/${JAVA_SITE}"
else
    button=`w3_url_escape "I'm Feeling Lucky"`
    escaped_args=`w3_url_of_arg $w3_args`
    w3_browse_url "http://www.google.com/search?q=${escaped_args}&sitesearch=java.sun.com/${JAVA_SITE}&btnI=${button}"
fi


More information about the Surfraw-devel mailing list