Initial revision
This commit is contained in:
		
							
								
								
									
										41
									
								
								w3m-doc/sample/README
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								w3m-doc/sample/README
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
|  | ||||
| <EFBFBD>Ȥ<EFBFBD><EFBFBD><EFBFBD> | ||||
|   perl w3mdoc.pl sample.wd > sample.html | ||||
|  | ||||
| Ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ||||
|  | ||||
| * @xxx.yyy@ | ||||
|  | ||||
|   @define <20><> @end <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>줿<EFBFBD>ͤ<EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>롣 | ||||
|  | ||||
| * @YYY(xxx)@ | ||||
|  | ||||
|   @code <20><> @end <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>줿<EFBFBD>ؿ<EFBFBD><D8BF><EFBFBD><EFBFBD>ƤӽФ<D3BD><D0A4><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>롣 | ||||
|  | ||||
|   <20><>) | ||||
|      URL(xxx)     xxx.url | ||||
|      LINK(xxx)    <A HREF="xxx.url">xxx.title</A> | ||||
|      MAILTO(xxx)  <A HREF="mailto:xxx.address">xxx.name</A> | ||||
|  | ||||
| <EFBFBD><EFBFBD><EFBFBD>ޥ<EFBFBD><EFBFBD>ɰ<EFBFBD><EFBFBD><EFBFBD> | ||||
|  | ||||
| * <20><><EFBFBD><EFBFBD> | ||||
|   @define | ||||
|     xxx.yyy    zzz | ||||
|   @end | ||||
|  | ||||
|   xxx.yyy <20><> zzz <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>롣xxx <20>ϰʲ<CFB0><CAB2>δؿ<CEB4><D8BF>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD>ˤ<EFBFBD><CBA4>ʤ롣 | ||||
|   <20><><EFBFBD><EFBFBD> define.wd <20>ȡ<F2BBB2BE> | ||||
|  | ||||
| * <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28>ؿ<EFBFBD><D8BF><EFBFBD><EFBFBD><EFBFBD>) | ||||
|   @code | ||||
|     <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ||||
|   @end | ||||
|  | ||||
|   w3mdoc <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Υ<EFBFBD><CEA5><EFBFBD><EFBFBD>ɤ<EFBFBD>ľ<EFBFBD>ܽ<DCBD><F1A4AFA1>Ȥꤢ<C8A4><EAA4A2><EFBFBD><EFBFBD> perl5<6C><35> | ||||
|   <20><><EFBFBD><EFBFBD> html.wd <20>ȡ<F2BBB2BE> | ||||
|  | ||||
| * <20><><EFBFBD>롼<F3A5AFA5><EBA1BC> | ||||
|   @include file | ||||
|  | ||||
|   <20>ե<EFBFBD><D5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> include <20><><EFBFBD>롣 | ||||
							
								
								
									
										4
									
								
								w3m-doc/sample/define.wd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								w3m-doc/sample/define.wd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| @define | ||||
| hsaka.url	http://www2u.biglobe.ne.jp/~hsaka/ | ||||
| hsaka.title	<09><><EFBFBD>ܹ<EFBFBD>§<EFBFBD>Υۡ<CEA5><DBA1><EFBFBD><EFBFBD>ڡ<EFBFBD><DAA1><EFBFBD> | ||||
| @end | ||||
							
								
								
									
										18
									
								
								w3m-doc/sample/html.wd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								w3m-doc/sample/html.wd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| @code | ||||
| sub URL { | ||||
|   $_[0]->CHECK(qw(url)); | ||||
|   $_[0]->{url}; | ||||
| } | ||||
| sub LINK { | ||||
|   $_[0]->CHECK(qw(url title)); | ||||
|   "<A HREF=\"$_[0]->{url}\">$_[0]->{title}</A>"; | ||||
| } | ||||
| sub LINK_SEC { | ||||
|   $_[0]->CHECK(qw(url section title)); | ||||
|   "<A HREF=\"$_[0]->{url}\">$_[0]->{section} $_[0]->{title}</A>"; | ||||
| } | ||||
| sub MAILTO { | ||||
|   $_[0]->CHECK(qw(address name)); | ||||
|   "<A HREF=\"mailto:$_[0]->{address}\">$_[0]->{name}</A>"; | ||||
| } | ||||
| @end | ||||
							
								
								
									
										268
									
								
								w3m-doc/sample/keymap.cgi
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										268
									
								
								w3m-doc/sample/keymap.cgi
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,268 @@ | ||||
| #!/usr/local/bin/perl | ||||
|  | ||||
| $QUERY = $ENV{'QUERY_STRING'}; | ||||
| $KEYMAP = "$ENV{'HOME'}/.w3m/keymap"; | ||||
|  | ||||
| if ($QUERY) { | ||||
| 	# &write_keymap($QUERY); | ||||
| 	print <<EOF; | ||||
| Content-Type: text/html | ||||
| w3m-control: DELETE_PREVBUF | ||||
| w3m-control: BACK | ||||
|  | ||||
| EOF | ||||
| 	exit; | ||||
| } | ||||
| &init_func(); | ||||
| @key = (); | ||||
| @func = (); | ||||
| @data = (); | ||||
| open(KEYMAP, $KEYMAP); | ||||
| while (<KEYMAP>) { | ||||
| 	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 <<EOF; | ||||
| Content-Type: text/html | ||||
|  | ||||
| <head><title>Keymap Setting</title></head> | ||||
| <h1>Keymap Setting</h1> | ||||
| <form action="file:///\$LIB/keymap.cgi"> | ||||
| <table> | ||||
| <tr><td> Key<td> Command<td> Argument | ||||
| <tr><td><input name=k_$N size=6> | ||||
| <td><select name=f_$N> | ||||
| EOF | ||||
| &print_func(); | ||||
| print <<EOF; | ||||
| </select> | ||||
| <td><input name=d_$N> | ||||
| <td><input type=submit name=ok value=Ok> | ||||
| <tr><td colspan=4><hr> | ||||
| EOF | ||||
| $i = 0; | ||||
| while(@key) { | ||||
| 	$k = &Q(shift @key); | ||||
| 	$f = shift @func; | ||||
| 	$d = &Q(shift @data); | ||||
| 	print <<EOF; | ||||
| <tr><td><input type=hidden name=k_$i value=\"$k\"> $k | ||||
| <td><select name=f_$i> | ||||
| EOF | ||||
| 	&print_func($f); | ||||
| 	print <<EOF; | ||||
| </select> | ||||
| <td><input name=d_$i value=\"$d\"> | ||||
| <td><input type=checkbox name=del_$i>Delete | ||||
| EOF | ||||
| 	$i++; | ||||
| } | ||||
| print <<EOF; | ||||
| </table> | ||||
| </form> | ||||
| 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; | ||||
| 	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 "<option selected>$_\n"; | ||||
| 		} else { | ||||
| 			print "<option>$_\n"; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| sub init_func { | ||||
| 	@FUNC_LIST = (); | ||||
| 	%FUNC_EXIST = (); | ||||
| 	while(<DATA>) { | ||||
| 		chop; | ||||
| 		push(@FUNC_LIST, $_); | ||||
| 		$FUNC_EXIST{$_} = 1; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| __END__ | ||||
| - - - - - - -  | ||||
| ABORT | ||||
| ADD_BOOKMARK | ||||
| BACK | ||||
| BEGIN | ||||
| BOOKMARK | ||||
| CENTER_H | ||||
| CENTER_V | ||||
| COOKIE | ||||
| DELETE_PREVBUF | ||||
| DICT_WORD | ||||
| DICT_WORD_AT | ||||
| DOWN | ||||
| DOWNLOAD | ||||
| EDIT | ||||
| EDIT_SCREEN | ||||
| END | ||||
| ESCBMAP | ||||
| ESCMAP | ||||
| EXEC_SHELL | ||||
| EXIT | ||||
| EXTERN | ||||
| EXTERN_LINK | ||||
| FRAME | ||||
| GOTO | ||||
| GOTO_LINE | ||||
| GOTO_LINK | ||||
| HELP | ||||
| HISTORY | ||||
| INFO | ||||
| INIT_MAILCAP | ||||
| INTERRUPT | ||||
| LEFT | ||||
| LINE_BEGIN | ||||
| LINE_END | ||||
| LINE_INFO | ||||
| LINK_BEGIN | ||||
| LINK_END | ||||
| LOAD | ||||
| MAIN_MENU | ||||
| MARK | ||||
| MARK_MID | ||||
| MARK_URL | ||||
| MENU | ||||
| MOUSE | ||||
| MOUSE_TOGGLE | ||||
| MOVE_DOWN | ||||
| MOVE_LEFT | ||||
| MOVE_RIGHT | ||||
| MOVE_UP	 | ||||
| NEXT_LINK | ||||
| NEXT_MARK | ||||
| NEXT_PAGE | ||||
| NEXT_WORD | ||||
| NOTHING | ||||
| NULL | ||||
| OPTIONS | ||||
| PCMAP | ||||
| PEEK | ||||
| PEEK_LINK | ||||
| PIPE_SHELL | ||||
| PREV_LINK | ||||
| PREV_MARK | ||||
| PREV_PAGE | ||||
| PREV_WORD | ||||
| PRINT | ||||
| QUIT | ||||
| READ_SHELL | ||||
| REDRAW | ||||
| REG_MARK | ||||
| RELOAD | ||||
| RIGHT | ||||
| SAVE | ||||
| SAVE_IMAGE | ||||
| SAVE_LINK | ||||
| SAVE_SCREEN | ||||
| SEARCH | ||||
| SEARCH_BACK | ||||
| SEARCH_FORE | ||||
| SEARCH_NEXT | ||||
| SEARCH_PREV | ||||
| SELECT | ||||
| SHELL | ||||
| SHIFT_LEFT | ||||
| SHIFT_RIGHT | ||||
| SOURCE | ||||
| SUSPEND | ||||
| UP | ||||
| VIEW | ||||
| VIEW_BOOKMARK | ||||
| VIEW_IMAGE | ||||
| WHEREIS	 | ||||
| WRAP_TOGGLE | ||||
							
								
								
									
										8
									
								
								w3m-doc/sample/s.wd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								w3m-doc/sample/s.wd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| @include html.wd | ||||
| @include define.wd | ||||
|  | ||||
| <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ץ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD> | ||||
| <P> | ||||
| \@hsaka.url\@ = @hsaka.url@ | ||||
| <BR> | ||||
| \@LINK(hsaka)\@ = @LINK(hsaka)@ | ||||
							
								
								
									
										6
									
								
								w3m-doc/sample/sample.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								w3m-doc/sample/sample.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
|  | ||||
| <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ץ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD> | ||||
| <P> | ||||
| @hsaka.url@ = http://www2u.biglobe.ne.jp/~hsaka/ | ||||
| <BR> | ||||
| @LINK(hsaka)@ = <A HREF="http://www2u.biglobe.ne.jp/~hsaka/"><EFBFBD><EFBFBD><EFBFBD>ܹ<EFBFBD>§<EFBFBD>Υۡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD><EFBFBD><EFBFBD></A> | ||||
							
								
								
									
										11
									
								
								w3m-doc/sample/sample.wd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								w3m-doc/sample/sample.wd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| @include html.wd | ||||
| @define | ||||
| hsaka.url	http://www2u.biglobe.ne.jp/~hsaka/ | ||||
| hsaka.title	<09><><EFBFBD>ܹ<EFBFBD>§<EFBFBD>Υۡ<CEA5><DBA1><EFBFBD><EFBFBD>ڡ<EFBFBD><DAA1><EFBFBD> | ||||
| @end | ||||
|  | ||||
| <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ץ<EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD> | ||||
| <P> | ||||
| \@hsaka.url\@ = @hsaka.url@ | ||||
| <BR> | ||||
| \@LINK(hsaka)\@ = @LINK(hsaka)@ | ||||
							
								
								
									
										102
									
								
								w3m-doc/sample/w3mdoc.pl
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										102
									
								
								w3m-doc/sample/w3mdoc.pl
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,102 @@ | ||||
| #!/usr/local/bin/perl | ||||
|  | ||||
| package w3mdoc; | ||||
|  | ||||
| sub CHECK { | ||||
|   my($a, @b) = @_; | ||||
|   for(@b) { | ||||
|     defined($a->{$_}) || die("\"$a->{id}.$_\" is not defined.\n"); | ||||
|   } | ||||
| } | ||||
|  | ||||
| sub DEF { | ||||
|   my($a, $b, $c) = @_; | ||||
|  | ||||
|   if (! defined($data->{$a})) { | ||||
|      $data->{$a} = bless { id => $a }; | ||||
|   }  | ||||
|   $data->{$a}{$b} = $c; | ||||
| } | ||||
|  | ||||
| sub SUB { | ||||
|   local($_) = @_; | ||||
|   my($a, $b); | ||||
|  | ||||
|   if (/^\@(\w+)\.(\w+)\@$/) { | ||||
|     ($a, $b) = ($1, $2); | ||||
|     defined($data->{$a}) || die("\"$a.$b\" is not defined.\n"); | ||||
|     $data->{$a}->CHECK($b); | ||||
|     return $data->{$a}{$b}; | ||||
|   } | ||||
|   if (/^\@(\w+)\((\w+)\)\@$/) { | ||||
|     ($a, $b) = ($1, $2); | ||||
|     defined(&{$a}) || die("\"$a()\" is not defined.\n"); | ||||
|     defined($data->{$b}) || die("\"$a($b)\" is not defined.\n"); | ||||
|     return $data->{$b}->$a(); | ||||
|   } | ||||
|   return '@'; | ||||
| } | ||||
|  | ||||
| package main; | ||||
|  | ||||
| @ARGV || unshift(@ARGV, "-"); | ||||
| while(@ARGV) { | ||||
|   $file = shift @ARGV; | ||||
|   &make_doc($file); | ||||
| } | ||||
|  | ||||
| sub make_doc { | ||||
|   my($file) = @_; | ||||
|   my($in_def, $in_code, $code, $a, $b); | ||||
|   local(*F); | ||||
|   local($_); | ||||
|  | ||||
|   open(F, $file) || die("$file: $!\n"); | ||||
|   $in_def = 0; | ||||
|   $in_code = 0; | ||||
|   while(<F>) { | ||||
|     if ($in_def) { | ||||
|       if (/^\@end/) { | ||||
|         $in_def = 0; | ||||
|         next; | ||||
|       } | ||||
|       s/^\s+//; | ||||
|       s/^(\w+)\.(\w+)// || next; | ||||
|       ($a, $b) = ($1, $2); | ||||
|       s/^\s+//; | ||||
|       s/\s+$//; | ||||
|       &w3mdoc::DEF($a, $b, $_); | ||||
|       next; | ||||
|     } | ||||
|     if ($in_code) { | ||||
|       if (/^\@end/) { | ||||
|         eval "package w3mdoc; $code"; | ||||
|         $in_code = 0; | ||||
|         next; | ||||
|       } | ||||
|       $code .= $_; | ||||
|       next; | ||||
|     } | ||||
|     if (/^\@define/) { | ||||
|       $in_def = 1; | ||||
|       next; | ||||
|     } | ||||
|     if (/^\@code/) { | ||||
|       $in_code = 1; | ||||
|       $code = ""; | ||||
|       next; | ||||
|     } | ||||
|     if (s/^\@include\s+//) { | ||||
|       s/\s+$//; | ||||
|       &make_doc($_); | ||||
|       next; | ||||
|     } | ||||
|     if (/^\@/) { | ||||
|       die("unknown command: $_"); | ||||
|     } | ||||
|     s/(\\@|\@(\w+(\.\w+|\(\w+\)))\@)/&w3mdoc::SUB($1)/eg; | ||||
|     print; | ||||
|   } | ||||
|   close(F); | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user