#!/usr/bin/env sh


readonly 'VERSION=framelinkmenu 2.0.4'



set -efu
umask '0022'
readonly "LC_ALL_ORG=${LC_ALL-}"
LC_ALL='C'
IFS=$(printf ' \t\n_')
IFS="${IFS%_}"
PATH="${PATH-}${PATH:+:}$(command -p getconf 'PATH')"
UNIX_STD='2003'         # HP-UX POSIX mode
XPG_SUS_ENV='ON'        # AIX POSIX mode
XPG_UNIX98='OFF'        # AIX UNIX 03 mode
POSIXLY_CORRECT='1'     # GNU Coreutils POSIX mode
COMMAND_MODE='unix2003' # macOS UNIX 03 mode
export 'LC_ALL' 'IFS' 'PATH' 'UNIX_STD' 'XPG_SUS_ENV' 'XPG_UNIX98' 'POSIXLY_CORRECT' 'COMMAND_MODE'




readonly 'EX_OK=0' # successful termination

readonly 'EX__BASE=64' # base value for error messages

readonly 'EX_USAGE=64'       # command line usage error
readonly 'EX_DATAERR=65'     # data format error
readonly 'EX_NOINPUT=66'     # cannot open input
readonly 'EX_NOUSER=67'      # addressee unknown
readonly 'EX_NOHOST=68'      # host name unknown
readonly 'EX_UNAVAILABLE=69' # service unavailable
readonly 'EX_SOFTWARE=70'    # internal software error
readonly 'EX_OSERR=71'       # system error (e.g., can't fork)
readonly 'EX_OSFILE=72'      # critical OS file missing
readonly 'EX_CANTCREAT=73'   # can't create (user) output file
readonly 'EX_IOERR=74'       # input/output error
readonly 'EX_TEMPFAIL=75'    # temp failure; user is invited to retry
readonly 'EX_PROTOCOL=76'    # remote error in protocol
readonly 'EX_NOPERM=77'      # permission denied
readonly 'EX_CONFIG=78'      # configuration error

readonly 'EX__MAX=78' # maximum listed value

trap 'case "${?}" in 0) end_call;; *) end_call "${EX_SOFTWARE}";; esac' 0 # EXIT
trap 'end_call 129' 1                                                     # SIGHUP
trap 'end_call 130' 2                                                     # SIGINT
trap 'end_call 131' 3                                                     # SIGQUIT
trap 'end_call 143' 15                                                    # SIGTERM

alias org_lc='LC_ALL="${LC_ALL_ORG}"'


end_call() {
	trap '' 0 # EXIT
	rm -fr -- ${tmpDir:+"${tmpDir}"}
	exit "${1:-0}"
}



option_error() {
	printf '%s: %s\n' "${0##*/}" "${1}" >&2
	printf "詳細については '%s' を実行してください。\\n" "${0##*/} --help" >&2

	end_call "${EX_USAGE}"
}



regex_match() {
	awk -- '
		BEGIN {
			for(i = 2; i < ARGC; i++) {
				if(ARGV[1] !~ ARGV[i]) {
					exit 1
				}
			}

			exit
		}
	' ${@+"${@}"} || return 1

	return 0
}



append_array_posix() {
	while [ 2 -le "${#}" ]; do
		__append_array_posix "${1}" "${2}"

		eval "shift 2; set -- '${1}'" '${@+"${@}"}'
	done
}


__append_array_posix() {
	set "${1}" "${2-}" ''

	until [ "${2#*\'}" '=' "${2}" ]; do
		set -- "${1}" "${2#*\'}" "${3}${2%%\'*}'\"'\"'"
	done

	eval "${1}=\"\${${1}-}\${${1}:+ }'\${3}\${2}'\""
}





abspath() {
	case "${2}" in
	'/'*) set -- "${1}" "${2}/" '' ;;
	*) set -- "${1}" "${3:-$PWD}/$2/" '' ;;
	esac

	while [ -n "${2}" ]; do
		case "${2%%/*}" in
		'' | '.') set -- "${1}" "${2#*/}" "${3}" ;;
		'..') set -- "${1}" "${2#*/}" "${3%/*}" ;;
		*) set -- "${1}" "${2#*/}" "${3}/${2%%/*}" ;;
		esac
	done

	eval "${1}=\"/\${3#/}\""
}


path_to_fileurl() {
	abspath "${1}" "${2}"

	eval "${1}=\"file://\$(printf '%s' \"\${${1}}\" | urlencode | sed -e 's/%2F/\//g')\""
}



datauri() {
	printf 'data:%s;base64,' "${1}"
	shift
	base64 -- ${@+"${@}"} | tr -d '\n'
}

option_category() {
	case "${OPTARG}" in
	'scheme') category='1' ;;
	'authority') category='2' ;;
	'path') category='3' ;;
	'query') category='4' ;;
	'fragment') category='5' ;;
	esac
}

parser_definition() {
	setup REST abbr:true error:option_error plus:true no:0 help:usage \
		-- 'Usage:' "  ${2##*/} [OPTION]... [FILE]..." \
		'' 'Options:'

	param :'append_array_posix attribute -a "${OPTARG}"' -a --attribute init:='cols=200,*' validate:'regex_match "${OPTARG}" "^[A-Za-z-]+="' var:'NANE=VALUE' -- 'frameset要素に属性を追加する'
	flag attribute --no-attribute init:@none on: no: -- '-a, --attribute をリセットする'
	param :option_category -c --category init:='scheme' pattern:'scheme | authority | path | query | fragment' var:'scheme | authority | path | query | fragment' -- 'サイドバーの URI を分類する'
	param main -m --main init:='data:text/plain,' var:URI -- 'メインページの URI を指定する'
	param output -o --menu-output init:'output="${HOME}/.w3mplus/cache"' var:PATH -- 'サイドバーの内容を PATH に出力する'
	param position -p --position init:='left' pattern:'left | right' var:'left | right' -- 'サイドバーの位置を指定する'
	param size -s --size init:='20' validate:'regex_match "${OPTARG}" "^(0|[1-9][0-9]*)$"' var:UNSIGNED_INTEGER -- 'サイドバーの文字列を切り詰める'
	param title -t --title init:='Links' var:TEXT -- 'フレームページのタイトルを指定する'
	disp :usage -h --help -- 'このヘルプを表示して終了する'
	disp VERSION -v --version -- 'バージョン情報を表示して終了する'

	msg -- '' 'Exit Status:' \
		'    0 - successful termination' \
		'   64 - command line usage error' \
		'   65 - data format error' \
		'   66 - cannot open input' \
		'   67 - addressee unknown' \
		'   68 - host name unknown' \
		'   69 - service unavailable' \
		'   70 - internal software error' \
		"   71 - system error (e.g., can't fork)" \
		'   72 - critical OS file missing' \
		"   73 - can't create (user) output file" \
		'   74 - input/output error' \
		'   75 - temp failure; user is invited to retry' \
		'   76 - remote error in protocol' \
		'   77 - permission denied' \
		'   78 - configuration error' \
		'  129 - received SIGHUP' \
		'  130 - received SIGINT' \
		'  131 - received SIGQUIT' \
		'  143 - received SIGTERM'
}

OPTARG='cols=200,*'
append_array_posix attribute -a "${OPTARG}"
OPTARG='scheme'
option_category
main='data:text/plain,'
output="${HOME}/.w3mplus/cache"
position='left'
size='20'
title='Links'
REST=''
parse() {
	OPTIND=$(($# + 1))
	while OPTARG= && [ $# -gt 0 ]; do
		set -- "${1%%\=*}" "${1#*\=}" "$@"
		while [ ${#1} -gt 2 ]; do
			case $1 in *[!a-zA-Z0-9_-]*) break ;; esac
			case '--attribute' in
			"$1")
				OPTARG=
				break
				;;
			$1*) OPTARG="$OPTARG --attribute" ;;
			esac
			case '--no-attribute' in
			"$1")
				OPTARG=
				break
				;;
			$1*) OPTARG="$OPTARG --no-attribute" ;;
			esac
			case '--category' in
			"$1")
				OPTARG=
				break
				;;
			$1*) OPTARG="$OPTARG --category" ;;
			esac
			case '--main' in
			"$1")
				OPTARG=
				break
				;;
			$1*) OPTARG="$OPTARG --main" ;;
			esac
			case '--menu-output' in
			"$1")
				OPTARG=
				break
				;;
			$1*) OPTARG="$OPTARG --menu-output" ;;
			esac
			case '--position' in
			"$1")
				OPTARG=
				break
				;;
			$1*) OPTARG="$OPTARG --position" ;;
			esac
			case '--size' in
			"$1")
				OPTARG=
				break
				;;
			$1*) OPTARG="$OPTARG --size" ;;
			esac
			case '--title' in
			"$1")
				OPTARG=
				break
				;;
			$1*) OPTARG="$OPTARG --title" ;;
			esac
			case '--help' in
			"$1")
				OPTARG=
				break
				;;
			$1*) OPTARG="$OPTARG --help" ;;
			esac
			case '--version' in
			"$1")
				OPTARG=
				break
				;;
			$1*) OPTARG="$OPTARG --version" ;;
			esac
			break
		done
		case ${OPTARG# } in
		*\ *)
			eval "set -- $OPTARG $1 $OPTARG"
			OPTIND=$((($# + 1) / 2)) OPTARG=$1
			shift
			while [ $# -gt "$OPTIND" ]; do
				OPTARG="$OPTARG, $1"
				shift
			done
			set "Ambiguous option: $1 (could be $OPTARG)" ambiguous "$@"
			option_error "$@" >&2 || exit $?
			echo "$1" >&2
			exit 1
			;;
		?*)
			[ "$2" = "$3" ] || OPTARG="$OPTARG=$2"
			shift 3
			eval 'set -- "${OPTARG# }"' ${1+'"$@"'}
			OPTARG=
			;;
		*) shift 2 ;;
		esac
		case $1 in
		--?*=*)
			OPTARG=$1
			shift
			eval 'set -- "${OPTARG%%\=*}" "${OPTARG#*\=}"' ${1+'"$@"'}
			;;
		--no-* | --without-*) unset OPTARG ;;
		-[acmopst]?*)
			OPTARG=$1
			shift
			eval 'set -- "${OPTARG%"${OPTARG#??}"}" "${OPTARG#??}"' ${1+'"$@"'}
			;;
		-[hv]?*)
			OPTARG=$1
			shift
			eval 'set -- "${OPTARG%"${OPTARG#??}"}" -"${OPTARG#??}"' ${1+'"$@"'}
			OPTARG=
			;;
		+*) unset OPTARG ;;
		esac
		case $1 in
		'-a' | '--attribute')
			[ $# -le 1 ] && set "required" "$1" && break
			OPTARG=$2
			regex_match "${OPTARG}" "^[A-Za-z-]+=" || {
				set -- regex_match:$? "$1" regex_match "${OPTARG}" "^[A-Za-z-]+="
				break
			}
			append_array_posix attribute -a "${OPTARG}"
			shift
			;;
		'--no-attribute')
			[ "${OPTARG:-}" ] && OPTARG=${OPTARG#*\=} && set "noarg" "$1" && break
			eval '[ ${OPTARG+x} ] &&:' && OPTARG='' || OPTARG=''
			attribute="$OPTARG"
			;;
		'-c' | '--category')
			[ $# -le 1 ] && set "required" "$1" && break
			OPTARG=$2
			case $OPTARG in scheme | authority | path | query | fragment) ;;
			*)
				set "pattern:scheme | authority | path | query | fragment" "$1"
				break
				;;
			esac
			option_category
			shift
			;;
		'-m' | '--main')
			[ $# -le 1 ] && set "required" "$1" && break
			OPTARG=$2
			main="$OPTARG"
			shift
			;;
		'-o' | '--menu-output')
			[ $# -le 1 ] && set "required" "$1" && break
			OPTARG=$2
			output="$OPTARG"
			shift
			;;
		'-p' | '--position')
			[ $# -le 1 ] && set "required" "$1" && break
			OPTARG=$2
			case $OPTARG in left | right) ;;
			*)
				set "pattern:left | right" "$1"
				break
				;;
			esac
			position="$OPTARG"
			shift
			;;
		'-s' | '--size')
			[ $# -le 1 ] && set "required" "$1" && break
			OPTARG=$2
			regex_match "${OPTARG}" "^(0|[1-9][0-9]*)$" || {
				set -- regex_match:$? "$1" regex_match "${OPTARG}" "^(0|[1-9][0-9]*)$"
				break
			}
			size="$OPTARG"
			shift
			;;
		'-t' | '--title')
			[ $# -le 1 ] && set "required" "$1" && break
			OPTARG=$2
			title="$OPTARG"
			shift
			;;
		'-h' | '--help')
			usage
			exit 0
			;;
		'-v' | '--version')
			echo "${VERSION}"
			exit 0
			;;
		--)
			shift
			while [ $# -gt 0 ]; do
				REST="${REST} \"\${$((OPTIND - $#))}\""
				shift
			done
			break
			;;
		[-+]?*)
			set "unknown" "$1"
			break
			;;
		*)
			REST="${REST} \"\${$((OPTIND - $#))}\""
			;;
		esac
		shift
	done
	[ $# -eq 0 ] && {
		OPTIND=1
		unset OPTARG
		return 0
	}
	case $1 in
	unknown) set "Unrecognized option: $2" "$@" ;;
	noarg) set "Does not allow an argument: $2" "$@" ;;
	required) set "Requires an argument: $2" "$@" ;;
	pattern:*) set "Does not match the pattern (${1#*:}): $2" "$@" ;;
	notcmd) set "Not a command: $2" "$@" ;;
	*) set "Validation error ($1): $2" "$@" ;;
	esac
	option_error "$@" >&2 || exit $?
	echo "$1" >&2
	exit 1
}
usage() {
	cat <<'GETOPTIONSHERE'
Usage:
  framelinkmenu [OPTION]... [FILE]...

Options:
  -a,     --attribute NANE=VALUE 
                              frameset要素に属性を追加する
          --no-attribute      -a, --attribute をリセットする
  -c,     --category scheme | authority | path | query | fragment 
                              サイドバーの URI を分類する
  -m,     --main URI          メインページの URI を指定する
  -o,     --menu-output PATH  サイドバーの内容を PATH に出力する
  -p,     --position left | right 
                              サイドバーの位置を指定する
  -s,     --size UNSIGNED_INTEGER 
                              サイドバーの文字列を切り詰める
  -t,     --title TEXT        フレームページのタイトルを指定する
  -h,     --help              このヘルプを表示して終了する
  -v,     --version           バージョン情報を表示して終了する

Exit Status:
    0 - successful termination
   64 - command line usage error
   65 - data format error
   66 - cannot open input
   67 - addressee unknown
   68 - host name unknown
   69 - service unavailable
   70 - internal software error
   71 - system error (e.g., can't fork)
   72 - critical OS file missing
   73 - can't create (user) output file
   74 - input/output error
   75 - temp failure; user is invited to retry
   76 - remote error in protocol
   77 - permission denied
   78 - configuration error
  129 - received SIGHUP
  130 - received SIGINT
  131 - received SIGQUIT
  143 - received SIGTERM
GETOPTIONSHERE
}

parse ${@+"${@}"}
eval "set -- ${REST}"

tmpDir=$(mktemp -d)
awkScript=$(
	cat <<-'__EOF__'



		function html_escape(string) {
			gsub(/&/, "\\&amp;", string)
			gsub(/</, "\\&lt;", string)
			gsub(/</, "\\&gt;", string)
			gsub(/'/, "\\&#39;", string)
			gsub(/"/, "\\&quot;", string)

			return string
		}





		function remove_control_character(string, except,  cc,char) {
			cc = "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\177\200\201\202\203\204\205\206\207\210\211\212\213\214"

			gsub(except, "", cc)

			for(char = ""; cc != ""; cc = substr(cc, 2)) {
				gsub(substr(cc, 1, 1), "", string)
			}

			return string
		}


		function safe_string(string) {
			return remove_control_character(string, "\011\012\015")
		}



		function url_decode(string, httpDecode,  p2c,result) {
			split("", p2c)

			p2c["00"] = "\000"; p2c["01"] = "\001";
			p2c["02"] = "\002"; p2c["03"] = "\003";
			p2c["04"] = "\004"; p2c["05"] = "\005";
			p2c["06"] = "\006"; p2c["07"] = "\007";
			p2c["08"] = "\010"; p2c["09"] = "\011";
			p2c["0A"] = p2c["0a"] = "\012"; p2c["0B"] = p2c["0b"] = "\013";
			p2c["0C"] = p2c["0c"] = "\014"; p2c["0D"] = p2c["0d"] = "\015";
			p2c["0E"] = p2c["0e"] = "\016"; p2c["0F"] = p2c["0f"] = "\017";
			p2c["10"] = "\020"; p2c["11"] = "\021";
			p2c["12"] = "\022"; p2c["13"] = "\023";
			p2c["14"] = "\024"; p2c["15"] = "\025";
			p2c["16"] = "\026"; p2c["17"] = "\027";
			p2c["18"] = "\030"; p2c["19"] = "\031";
			p2c["1A"] = p2c["1a"] = "\032"; p2c["1B"] = p2c["1b"] = "\033";
			p2c["1C"] = p2c["1c"] = "\034"; p2c["1D"] = p2c["1d"] = "\035";
			p2c["1E"] = p2c["1e"] = "\036"; p2c["1F"] = p2c["1f"] = "\037";
			p2c["20"] = "\040"; p2c["21"] = "\041";
			p2c["22"] = "\042"; p2c["23"] = "\043";
			p2c["24"] = "\044"; p2c["25"] = "\045";
			p2c["26"] = "\046"; p2c["27"] = "\047";
			p2c["28"] = "\050"; p2c["29"] = "\051";
			p2c["2A"] = p2c["2a"] = "\052"; p2c["2B"] = p2c["2b"] = "\053";
			p2c["2C"] = p2c["2c"] = "\054"; p2c["2D"] = p2c["2d"] = "\055";
			p2c["2E"] = p2c["2e"] = "\056"; p2c["2F"] = p2c["2f"] = "\057";
			p2c["30"] = "\060"; p2c["31"] = "\061";
			p2c["32"] = "\062"; p2c["33"] = "\063";
			p2c["34"] = "\064"; p2c["35"] = "\065";
			p2c["36"] = "\066"; p2c["37"] = "\067";
			p2c["38"] = "\070"; p2c["39"] = "\071";
			p2c["3A"] = p2c["3a"] = "\072"; p2c["3B"] = p2c["3b"] = "\073";
			p2c["3C"] = p2c["3c"] = "\074"; p2c["3D"] = p2c["3d"] = "\075";
			p2c["3E"] = p2c["3e"] = "\076"; p2c["3F"] = p2c["3f"] = "\077";
			p2c["40"] = "\100"; p2c["41"] = "\101";
			p2c["42"] = "\102"; p2c["43"] = "\103";
			p2c["44"] = "\104"; p2c["45"] = "\105";
			p2c["46"] = "\106"; p2c["47"] = "\107";
			p2c["48"] = "\110"; p2c["49"] = "\111";
			p2c["4A"] = p2c["4a"] = "\112"; p2c["4B"] = p2c["4b"] = "\113";
			p2c["4C"] = p2c["4c"] = "\114"; p2c["4D"] = p2c["4d"] = "\115";
			p2c["4E"] = p2c["4e"] = "\116"; p2c["4F"] = p2c["4f"] = "\117";
			p2c["50"] = "\120"; p2c["51"] = "\121";
			p2c["52"] = "\122"; p2c["53"] = "\123";
			p2c["54"] = "\124"; p2c["55"] = "\125";
			p2c["56"] = "\126"; p2c["57"] = "\127";
			p2c["58"] = "\130"; p2c["59"] = "\131";
			p2c["5A"] = p2c["5a"] = "\132"; p2c["5B"] = p2c["5b"] = "\133";
			p2c["5C"] = p2c["5c"] = "\134"; p2c["5D"] = p2c["5d"] = "\135";
			p2c["5E"] = p2c["5e"] = "\136"; p2c["5F"] = p2c["5f"] = "\137";
			p2c["60"] = "\140"; p2c["61"] = "\141";
			p2c["62"] = "\142"; p2c["63"] = "\143";
			p2c["64"] = "\144"; p2c["65"] = "\145";
			p2c["66"] = "\146"; p2c["67"] = "\147";
			p2c["68"] = "\150"; p2c["69"] = "\151";
			p2c["6A"] = p2c["6a"] = "\152"; p2c["6B"] = p2c["6b"] = "\153";
			p2c["6C"] = p2c["6c"] = "\154"; p2c["6D"] = p2c["6d"] = "\155";
			p2c["6E"] = p2c["6e"] = "\156"; p2c["6F"] = p2c["6f"] = "\157";
			p2c["70"] = "\160"; p2c["71"] = "\161";
			p2c["72"] = "\162"; p2c["73"] = "\163";
			p2c["74"] = "\164"; p2c["75"] = "\165";
			p2c["76"] = "\166"; p2c["77"] = "\167";
			p2c["78"] = "\170"; p2c["79"] = "\171";
			p2c["7A"] = p2c["7a"] = "\172"; p2c["7B"] = p2c["7b"] = "\173";
			p2c["7C"] = p2c["7c"] = "\174"; p2c["7D"] = p2c["7d"] = "\175";
			p2c["7E"] = p2c["7e"] = "\176"; p2c["7F"] = p2c["7f"] = "\177";
			p2c["80"] = "\200"; p2c["81"] = "\201";
			p2c["82"] = "\202"; p2c["83"] = "\203";
			p2c["84"] = "\204"; p2c["85"] = "\205";
			p2c["86"] = "\206"; p2c["87"] = "\207";
			p2c["88"] = "\210"; p2c["89"] = "\211";
			p2c["8A"] = p2c["8a"] = "\212"; p2c["8B"] = p2c["8b"] = "\213";
			p2c["8C"] = p2c["8c"] = "\214"; p2c["8D"] = p2c["8d"] = "\215";
			p2c["8E"] = p2c["8e"] = "\216"; p2c["8F"] = p2c["8f"] = "\217";
			p2c["90"] = "\220"; p2c["91"] = "\221";
			p2c["92"] = "\222"; p2c["93"] = "\223";
			p2c["94"] = "\224"; p2c["95"] = "\225";
			p2c["96"] = "\226"; p2c["97"] = "\227";
			p2c["98"] = "\230"; p2c["99"] = "\231";
			p2c["9A"] = p2c["9a"] = "\232"; p2c["9B"] = p2c["9b"] = "\233";
			p2c["9C"] = p2c["9c"] = "\234"; p2c["9D"] = p2c["9d"] = "\235";
			p2c["9E"] = p2c["9e"] = "\236"; p2c["9F"] = p2c["9f"] = "\237";
			p2c["A0"] = p2c["a0"] = "\240"; p2c["A1"] = p2c["a1"] = "\241";
			p2c["A2"] = p2c["a2"] = "\242"; p2c["A3"] = p2c["a3"] = "\243";
			p2c["A4"] = p2c["a4"] = "\244"; p2c["A5"] = p2c["a5"] = "\245";
			p2c["A6"] = p2c["a6"] = "\246"; p2c["A7"] = p2c["a7"] = "\247";
			p2c["A8"] = p2c["a8"] = "\250"; p2c["A9"] = p2c["a9"] = "\251";
			p2c["AA"] = p2c["aA"] = p2c["Aa"] = p2c["aa"] = "\252";
			p2c["AB"] = p2c["aB"] = p2c["Ab"] = p2c["ab"] = "\253";
			p2c["AC"] = p2c["aC"] = p2c["Ac"] = p2c["ac"] = "\254";
			p2c["AD"] = p2c["aD"] = p2c["Ad"] = p2c["ad"] = "\255";
			p2c["AE"] = p2c["aE"] = p2c["Ae"] = p2c["ae"] = "\256";
			p2c["AF"] = p2c["aF"] = p2c["Af"] = p2c["af"] = "\257";
			p2c["B0"] = p2c["b0"] = "\260"; p2c["B1"] = p2c["b1"] = "\261";
			p2c["B2"] = p2c["b2"] = "\262"; p2c["B3"] = p2c["b3"] = "\263";
			p2c["B4"] = p2c["b4"] = "\264"; p2c["B5"] = p2c["b5"] = "\265";
			p2c["B6"] = p2c["b6"] = "\266"; p2c["B7"] = p2c["b7"] = "\267";
			p2c["B8"] = p2c["b8"] = "\270"; p2c["B9"] = p2c["b9"] = "\271";
			p2c["BA"] = p2c["bA"] = p2c["Ba"] = p2c["ba"] = "\272";
			p2c["BB"] = p2c["bB"] = p2c["Bb"] = p2c["bb"] = "\273";
			p2c["BC"] = p2c["bC"] = p2c["Bc"] = p2c["bc"] = "\274";
			p2c["BD"] = p2c["bD"] = p2c["Bd"] = p2c["bd"] = "\275";
			p2c["BE"] = p2c["bE"] = p2c["Be"] = p2c["be"] = "\276";
			p2c["BF"] = p2c["bF"] = p2c["Bf"] = p2c["bf"] = "\277";
			p2c["C0"] = p2c["c0"] = "\300"; p2c["C1"] = p2c["c1"] = "\301";
			p2c["C2"] = p2c["c2"] = "\302"; p2c["C3"] = p2c["c3"] = "\303";
			p2c["C4"] = p2c["c4"] = "\304"; p2c["C5"] = p2c["c5"] = "\305";
			p2c["C6"] = p2c["c6"] = "\306"; p2c["C7"] = p2c["c7"] = "\307";
			p2c["C8"] = p2c["c8"] = "\310"; p2c["C9"] = p2c["c9"] = "\311";
			p2c["CA"] = p2c["cA"] = p2c["Ca"] = p2c["ca"] = "\312";
			p2c["CB"] = p2c["cB"] = p2c["Cb"] = p2c["cb"] = "\313";
			p2c["CC"] = p2c["cC"] = p2c["Cc"] = p2c["cc"] = "\314";
			p2c["CD"] = p2c["cD"] = p2c["Cd"] = p2c["cd"] = "\315";
			p2c["CE"] = p2c["cE"] = p2c["Ce"] = p2c["ce"] = "\316";
			p2c["CF"] = p2c["cF"] = p2c["Cf"] = p2c["cf"] = "\317";
			p2c["D0"] = p2c["d0"] = "\320"; p2c["D1"] = p2c["d1"] = "\321";
			p2c["D2"] = p2c["d2"] = "\322"; p2c["D3"] = p2c["d3"] = "\323";
			p2c["D4"] = p2c["d4"] = "\324"; p2c["D5"] = p2c["d5"] = "\325";
			p2c["D6"] = p2c["d6"] = "\326"; p2c["D7"] = p2c["d7"] = "\327";
			p2c["D8"] = p2c["d8"] = "\330"; p2c["D9"] = p2c["d9"] = "\331";
			p2c["DA"] = p2c["dA"] = p2c["Da"] = p2c["da"] = "\332";
			p2c["DB"] = p2c["dB"] = p2c["Db"] = p2c["db"] = "\333";
			p2c["DC"] = p2c["dC"] = p2c["Dc"] = p2c["dc"] = "\334";
			p2c["DD"] = p2c["dD"] = p2c["Dd"] = p2c["dd"] = "\335";
			p2c["DE"] = p2c["dE"] = p2c["De"] = p2c["de"] = "\336";
			p2c["DF"] = p2c["dF"] = p2c["Df"] = p2c["df"] = "\337";
			p2c["E0"] = p2c["e0"] = "\340"; p2c["E1"] = p2c["e1"] = "\341";
			p2c["E2"] = p2c["e2"] = "\342"; p2c["E3"] = p2c["e3"] = "\343";
			p2c["E4"] = p2c["e4"] = "\344"; p2c["E5"] = p2c["e5"] = "\345";
			p2c["E6"] = p2c["e6"] = "\346"; p2c["E7"] = p2c["e7"] = "\347";
			p2c["E8"] = p2c["e8"] = "\350"; p2c["E9"] = p2c["e9"] = "\351";
			p2c["EA"] = p2c["eA"] = p2c["Ea"] = p2c["ea"] = "\352";
			p2c["EB"] = p2c["eB"] = p2c["Eb"] = p2c["eb"] = "\353";
			p2c["EC"] = p2c["eC"] = p2c["Ec"] = p2c["ec"] = "\354";
			p2c["ED"] = p2c["eD"] = p2c["Ed"] = p2c["ed"] = "\355";
			p2c["EE"] = p2c["eE"] = p2c["Ee"] = p2c["ee"] = "\356";
			p2c["EF"] = p2c["eF"] = p2c["Ef"] = p2c["ef"] = "\357";
			p2c["F0"] = p2c["f0"] = "\360"; p2c["F1"] = p2c["f1"] = "\361";
			p2c["F2"] = p2c["f2"] = "\362"; p2c["F3"] = p2c["f3"] = "\363";
			p2c["F4"] = p2c["f4"] = "\364"; p2c["F5"] = p2c["f5"] = "\365";
			p2c["F6"] = p2c["f6"] = "\366"; p2c["F7"] = p2c["f7"] = "\367";
			p2c["F8"] = p2c["f8"] = "\370"; p2c["F9"] = p2c["f9"] = "\371";
			p2c["FA"] = p2c["fA"] = p2c["Fa"] = p2c["fa"] = "\372";
			p2c["FB"] = p2c["fB"] = p2c["Fb"] = p2c["fb"] = "\373";
			p2c["FC"] = p2c["fC"] = p2c["Fc"] = p2c["fc"] = "\374";
			p2c["FD"] = p2c["fD"] = p2c["Fd"] = p2c["fd"] = "\375";
			p2c["FE"] = p2c["fE"] = p2c["Fe"] = p2c["fe"] = "\376";
			p2c["FF"] = p2c["fF"] = p2c["Ff"] = p2c["ff"] = "\377";

			if(httpDecode) {
				gsub(/\+/, " ", string)
			}

			for(result = ""; match(string, /%[0-9A-Fa-f]{2}/); string = substr(string, RSTART + RLENGTH)) {
				result = result substr(string, 1, RSTART - 1) p2c[substr(string, RSTART + 1, 2)]
			}

			return result string
		}

			BEGIN {
				split("", previous)
			}

			{
				uri = ""

				for(i = 1; i < start; i++) {
					uri = uri $i
				}

				for(i = start; i <= 5; i++) {
					segment = $i
					uri = uri segment

					if(segment != previous[i]) {
						for(j = i + 1; previous[j] != ""; j++) {
							printf("</li></ul>")
							previous[j] = ""
						}

						if(previous[i] == "") {
							printf("<ul>")
						} else {
							printf("</li>")
						}

						printf("<li><a title=\"%s\" target=\"main\" href=\"%s\">%s%s</a>", html_escape(safe_string(url_decode(segment))), html_escape(safe_string(uri)), html_escape(substr(safe_string(segment), 1, size)), size < length(segment) ? "..." : "")

						previous[i] = segment
					}
				}
			}

			END {
				for(j = start; previous[j] != ""; j++) {
					printf("</li></ul>")
				}
			}
	__EOF__
)

sed -e '/["[:blank:]]/d; s/^/"/; s/$/"/' -- ${@+"${@}"} |
	org_lc xargs -E "" uricheck --field 'scheme!,authority!,path,query!,fragment!' |
	sort | uniq |
	sort -k "${category}" |
	awk -v "size=${size}" -v "start=${category}" -- "${awkScript}" |
	org_lc printhtml --title 'Menu page' -- - >"${tmpDir}/file"

case "${output}" in
'') output=$(datauri 'text/html;charset=UTF-8' "${tmpDir}/file") ;;
*)
	if [ '!' -e "${output}" ]; then
		outputDir=$(
			dirname -- "${output}"
			printf '_'
		)
		mkdir -p -- "${outputDir%?_}"

		: >"${output}"
	fi

	if [ -d "${output}" ]; then
		output="${output}/menu-$(cksum "${tmpDir}/file" | cut -d ' ' -f '1-2' | tr ' ' '-').html"

		cat -- "${tmpDir}/file" >"${output}"
	elif [ -f "${output}" ]; then
		cat -- "${tmpDir}/file" >"${output}"
	else
		printf "%s: '%s' は通常ファイルではありません。\\n" "${0##*/}" "${output}" >&2
		printf "詳細については '%s' を実行してください。\\n" "${0##*/} --help" >&2

		end_call "${EX_DATAERR}"
	fi
	;;
esac

path_to_fileurl 'menu' "${output}"

case "${position}" in
'left') eval org_lc "htmlframe ${attribute} --title \"\${title}\" --n1 'menu' --n2 'main' --t1 'Menu page' --t2 'Main page' -- \"\${menu}\" \"\${main}\"" ;;
'right') eval org_lc "htmlframe ${attribute} --title \"\${title}\" --n1 'main' --n2 'menu' --t1 'Main page' --t2 'Menu page' -- \"\${main}\" \"\${menu}\"" ;;
esac
