Rebol > Man

Man

Table of contents
No headers
man: func [
	"Prints information about words and values, and wiki link."
	'word [any-type!]
	/local value args item type-name refmode types attrs rtype doc-class? link alpha other alpha-rule nonalpha-rule
] [
	if unset? get/any 'word [
		print trim/auto {
^-^-^-To use HELP, supply a word or value as its
^-^-^-argument:
^-^-^-
^-^-^-^-help insert
^-^-^-^-help system
^-^-^-^-help system/script

^-^-^-To view all words that match a pattern use a
^-^-^-string or partial word:

^-^-^-^-help "path"
^-^-^-^-help to-

^-^-^-To see words with values of a specific datatype:

^-^-^-^-help native!
^-^-^-^-help datatype!

^-^-^-Word completion:

^-^-^-^-The command line can perform word
^-^-^-^-completion. Type a few chars and press TAB
^-^-^-^-to complete the word. If nothing happens,
^-^-^-^-there may be more than one word that
^-^-^-^-matches. Press TAB again to see choices.

^-^-^-^-Local filenames can also be completed.
^-^-^-^-Begin the filename with a %.

^-^-^-Other useful functions:

^-^-^-^-about - see general product info
^-^-^-^-usage - view program options
^-^-^-^-license - show terms of user license
^-^-^-^-source func - view source of a function
^-^-^-^-upgrade - updates your copy of REBOL
^-^-^-
^-^-^-More information: http://www.rebol.com/docs.html
^-^-}
		exit
	]
	if all [word? :word not value? :word] [word: mold :word]
	if any [string? :word all [word? :word datatype? get :word]] [
		types: dump-obj/match system/words :word
		sort types
		if not empty? types [
			print ["Found these words:" newline types]
			exit
		]
		print ["No information on" word "(word has no value)"]
		exit
	]
	type-name: func [value] [
		value: mold type? :value
		clear back tail value
		join either find "aeiou" first value ["an "] ["a "] value
	]
	if not any [word? :word path? :word] [
		print [mold :word "is" type-name :word]
		exit
	]
	value: either path? :word [first reduce reduce [word]] [get :word]
	if not any-function? :value [
		prin [uppercase mold word "is" type-name :value "of value: "]
		print either object? value [print "" dump-obj value] [mold :value]
		exit
	]
	args: third :value
	prin "USAGE:^/^-"
	if not op? :value [prin append uppercase mold word " "]
	while [not tail? args] [
		item: first args
		if :item = /local [break]
		if any [all [any-word? :item not set-word? :item] refinement? :item] [
			prin append mold :item " "
			if op? :value [prin append uppercase mold word " " value: none]
		]
		args: next args
	]
	print ""
	args: head args
	value: get word
	print "^/DESCRIPTION:"
	either string? pick args 1 [
		print [tab first args]
		args: next args
	] [
		print "^-(undocumented)"
	]
	print [tab uppercase mold word "is" type-name :value "value."]

	doc-class?: either find type-name :value "datatype" ["datatypes"] ["functions"]

	if block? pick args 1 [
		attrs: first args
		args: next args
	]
	if tail? args [exit]
	while [not tail? args] [
		item: first args
		args: next args
		if :item = /local [break]
		either not refinement? :item [
			all [set-word? :item :item = to-set-word 'return block? first args rtype: first args]
			if none? refmode [
				print "^/ARGUMENTS:"
				refmode: 'args
			]
		] [
			if refmode <> 'refs [
				print "^/REFINEMENTS:"
				refmode: 'refs
			]
		]
		either refinement? :item [
			prin [tab mold item]
			if string? pick args 1 [prin [" --" first args] args: next args]
			print ""
		] [
			if all [any-word? :item not set-word? :item] [
				if refmode = 'refs [prin tab]
				prin [tab :item "-- "]
				types: if block? pick args 1 [args: next args first back args]
				if string? pick args 1 [prin [first args ""] args: next args]
				if not types [types: 'any]
				prin rejoin ["(Type: " types ")"]
				print ""
			]
		]

	]
	if rtype [print ["^/RETURNS:^/^-" rtype]]
	if attrs [
		print "^/(SPECIAL ATTRIBUTES)"
		while [not tail? attrs] [
			value: first attrs
			attrs: next attrs
			if any-word? value [
				prin [tab value]
				if string? pick attrs 1 [
					prin [" -- " first attrs]
					attrs: next attrs
				]
				print ""
			]
		]
	]
	; print out wiki link

	; ? => -q
	; / => -div
	; ~
	; < => lt
	; > => gt
	; ! => ex
	; - => 
	; -- => -
	; + => plu
	; * => mul

	link: copy ""
	alpha: charset [#"a" - #"z" #"A" - #"Z"]
	other: complement alpha

	alpha-rule: [some [copy part some alpha (append link part) opt [#"-" (append link "-")]] [end | "?" end (append link "-q") | "~" end (append link "~")]]
	nonalpha-rule: [copy part some other (
			append link "z"
			; need to translate these chars
			parse part [some [
					"/" (append link "-div") |
					"?" (append link "-q") |
					"<" (append link "-lt") |
					">" (append link "-gt") |
					"!" (append link "-ex") |
					"--" (append link "--") |
					"-" (append link "-") |
					"+" (append link "-plu") |
					"*" (append link "-mul") |
					"=" (append link "-eq")
				] end]
		)
	]

	print "WIKI:"
	print rejoin ["^-" http://www.rebol.com/r3/docs/ doc-class? "/" either parse form word [alpha-rule | nonalpha-rule] [link] ["unknown"] %.html]
	exit
]

Retrieved from "http://rebol.wik.is/Man"

Tag page
You must login to post a comment.
wik.is
Wik.is portal where you can upload your ideas and interests and educational mind set for a free website account please apply here