#!/bin/sh

alterator_api_version=1
. alterator-sh-functions

dirs="/usr/share/alt-notes 
      /usr/share/alt-license 
      /var/lib/install3/licenses"

on_message() {
	case "$in_action" in
        	read)
			local name="${in_name:-license}"
			local license_file= path lang languages

			languages="$(printf '%s' "$in_language" |tr ';' ' ') all"
	
			for path in $dirs; do
			    for lang in $languages; do
			    	    case "$lang" in
				    	    POSIX|C|all) lang="all";;
					    *) lang="$(printf %s "${lang%%_*}" |tr '[A-Z]' '[a-z]')";;
				    esac

		    		html_file="$path/$name.$lang.html"
				[ ! -s "$html_file" ] || break 2
			    done
			done

			if [ -s "$html_file" ]; then
				write_string_param "url" "$html_file"
			else
				write_error "`_ "File not found"` $name"
			fi
                        ;;
        esac
}

message_loop
