From 68a07bf03b7624c9924065cce9ffa45497225834 Mon Sep 17 00:00:00 2001 From: Akinori Ito Date: Thu, 8 Nov 2001 05:14:08 +0000 Subject: Initial revision --- w3m-doc/sample/keymap.cgi | 268 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100755 w3m-doc/sample/keymap.cgi (limited to 'w3m-doc/sample/keymap.cgi') diff --git a/w3m-doc/sample/keymap.cgi b/w3m-doc/sample/keymap.cgi new file mode 100755 index 0000000..f68f5fb --- /dev/null +++ b/w3m-doc/sample/keymap.cgi @@ -0,0 +1,268 @@ +#!/usr/local/bin/perl + +$QUERY = $ENV{'QUERY_STRING'}; +$KEYMAP = "$ENV{'HOME'}/.w3m/keymap"; + +if ($QUERY) { + # &write_keymap($QUERY); + print <) { + s/^keymap\s+// || next; + (($k, $_) = &getQWord($_)) || next; + (($f, $_) = &getWord($_)) || next; + $FUNC_EXIST{$f} || next; + ($d, $_) = &getQWord($_); + push(@key, $k); + push(@func, $f); + push(@data, $d); +} +close(KEYMAP); + +$N = @key; + +print <Keymap Setting +

Keymap Setting

+
+ +
 Key Command Argument +
+ + +

+EOF +$i = 0; +while(@key) { + $k = &Q(shift @key); + $f = shift @func; + $d = &Q(shift @data); + print <
 $k + +Delete +EOF + $i++; +} +print < + +EOF + +sub write_keymap { + local($query) = @_; + @key = (); + @func = (); + @data = (); + + for $q (split('&', $query)) { + ($_, $d) = split('=', $q); + if (s/^k_//) { + $key[$_] = $d; + } elsif (s/^f_//) { + $func[$_] = $d; + } elsif (s/^d_//) { + $data[$_] = $d; + } elsif (s/^del_//) { + $del[$_] = 1; + } + } + open(KEYMAP, "> ${KEYMAP}") || next; + while(@key) { + $k = &UQ(shift @key); + $f = shift @func; + $d = &UQ(shift @data); + ($f =~ /^\w/) || next; + (shift @del) && next; + print KEYMAP "keymap\t$k\t$f"; + if ($d ne '') { + if ($d =~ /[\"\'\\\s]/) { + $d =~ s/([\"\\])/\\$1/g; + print KEYMAP "\t\t\"$d\""; + } else { + $d =~ s/([\"\\])/\\$1/g; + print KEYMAP "\t\t$d"; + } + } + print KEYMAP "\n"; + } + close(KEYMAP); +} + +sub UQ { + local($_) = @_; + s/\+/ /g; + s/%([\da-f][\da-f])/pack('c', hex($1))/egi; + return $_; +} + +sub Q { + local($_) = @_; + s/\&/\&/g; + s/\/\>/g; + s/\"/\"/g; + return $_; +} + +sub getQWord { + local($_) = @_; + local($x) = ''; + s/^\s+//; + while($_ ne '') { + if (s/^\'(([^\'\\]|\\.)*)\'// || + s/^\"(([^\"\\]|\\.)*)\"// || + s/^([^\'\"\\\s]+)// || s/^\\(.)//) { + $x .= $1; + } else { + last; + } + } + return ($x, $_); +} + +sub getWord { + local($_) = @_; + s/^\s+//; + s/^(\S+)// || return (); + return ($1, $_); +} + +sub print_func { + local($f) = @_; + for(@FUNC_LIST) { + if ($f eq $_) { + print "