summaryrefslogtreecommitdiff
path: root/getxbookgui.tcl
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2012-04-22 23:59:59 +0100
committerNick White <git@njw.me.uk>2012-04-22 23:59:59 +0100
commit0a115a8d8b8cc65c224ccbe5eb466c64f4716d2d (patch)
tree3129cd0792225f830c7e5d87098135bc97c85f3d /getxbookgui.tcl
parent5af2510532c2fe9a1cdf86398a523c7f4c5690fc (diff)
Simplify gui string matching
Diffstat (limited to 'getxbookgui.tcl')
-rwxr-xr-xgetxbookgui.tcl36
1 files changed, 16 insertions, 20 deletions
diff --git a/getxbookgui.tcl b/getxbookgui.tcl
index 53d19e3..8d9467a 100755
--- a/getxbookgui.tcl
+++ b/getxbookgui.tcl
@@ -2,9 +2,12 @@
# See COPYING file for copyright and license details.
package require Tk
-set bins {{getgbook "Google Book ID" "Google\nBook Preview"} \
- {getabook "ISBN 10" "Amazon Look\nInside The Book"} \
- {getbnbook "ISBN 13" "Barnes & Noble\nBook Viewer"}}
+set bins {{getgbook "Google Book ID" "Google\nBook Preview" \
+ "http*://books.google.com/*" {[&?]id=([^&]*)}} \
+ {getabook "ISBN 10" "Amazon Look\nInside The Book" \
+ "http*://*amazon*/*" {/([0-9]{10}}} \
+ {getbnbook "ISBN 13" "Barnes & Noble\nBook Viewer" \
+ "http*://www.barnesandnoble.com/*" ""}}
set binselected 0
set dling 0
set manual 0
@@ -38,24 +41,17 @@ proc go {} {
}
proc parseurl {url} {
- set bookid ""
- if { [string match "http*://books.google.com/*" "$url"] } {
- selbin 0
- if {[regexp {[&?]id=([^&]*)} $url m sub]} {
- set bookid $sub
+ global bins
+ for {set i 0} {$i < [llength $bins]} {incr i} {
+ set b [lindex $bins $i]
+ if { [string match [lindex $b 3] "$url"] } {
+ selbin $i
+ set binregex [lindex $b 4]
+ if {"$binregex" != "" && [regexp "$binregex" $url m sub]} {
+ .input.id delete 0 end
+ .input.id insert 0 "$sub"
+ }
}
- } elseif { [string match "http*://*amazon*/*" "$url"] } {
- selbin 1
- if {[regexp {/([0-9]{10})/} $url m sub]} {
- set bookid $sub
- }
- } elseif { [string match "http*://www.barnesandnoble.com/*" "$url"] } {
- selbin 2
- # isbn-13 isn't included in b&n book urls, sadly
- }
- if { "$bookid" != "" } {
- .input.id delete 0 end
- .input.id insert 0 "$bookid"
}
}