Plan 9 from Bell Labs’s /usr/web/sources/contrib/lee/misc/dict.cn

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

# by Lee Duhem(lee.duhem@gmail.com)

# To use this script, you need set your font environment variable to
# some chinese font, for example fongsong.9.font.
# You can set this in your profile file: $home/lib/profile.

rfork e

usesearch = 0
usews = 0
usemini = 1

fn usage{
	echo 'usage: dict.cn [-amsw] word(s)'
	exit usage
}

fn search{
	hget 'http://dict.cn/search/?q='^$1 \
	| tcs -f gb2312 | htmlfmt \
	| tail +11l | sed '/^加入生词本|^Google提供的广告/ q'
}

fn ws{
	# poor man's XML converter
	hget 'http://dict.cn/ws.php?utf8=true&q='^$1 \
	| tail +7l | sed 's/^<def>|<\/def>$|<\/dict>$//;'
}

fn mini{
	hget 'http://dict.cn/mini.php?q='^$1 \
	| tcs -f gb2312 | htmlfmt
}

###

if(~ $#* 0)
	usage

while(! ~ $#* 0 && ~ $1 -*){
	switch($1){
		case -m
			usemini = 1
			usesearch = 0
			usews = 0
		case -s
			usemini = 0
			usesearch = 1
			usews= 0
		case -w
			usemini = 0
			usesearch = 0
			usews = 1
		case -a
			usemini = 1
			usesearch = 1
			usews = 1
		case -*
			usage
		}
		shift
}

while(! ~ $#* 0){
	if(~ $usesearch 1)
		search $1
	if(~ $usews 1)
		ws $1
	if(~ $usemini 1)
		mini $1
	shift
}

exit ''

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.