#!/bin/sh eecho() { echo "$@" >&2 } usage() { eecho -e "Usage: `basename ${0}` [] [...]" eecho -e "\tTool for multiskkserv." eecho -e "\tYou can use standard input instead of input files by not giving input files." eecho -e "options:" eecho -e "\t-s \tOutput skkdic file." eecho -e "\t\t\t\tNote that this output might be invalid." eecho -e "\t\t\t\tUse tools like skk-tools to use the output." eecho -e "\t-c \t\tOutput cdb file." eecho -e "\t-d \t\tCommand to execute when done." } OUTPUT_SKK= OUTPUT_CDB= DONE_COMMAND= case "$1" in "--help"|"-h") usage exit ;; esac while getopts "d:s:c:" OPT ; do case "$OPT" in "s") # skkdic output file OUTPUT_SKK="$OPTARG" ;; "d") # command DONE_COMMAND="$OPTARG" ;; "c") # cdb output file OUTPUT_CDB="$OPTARG" ;; esac done shift $(( ${OPTIND} - 1 )) if [ $# -lt 1 ] ; then usage exit 2 fi OUTPUT_FILE="$1" AWK_CONVERT_SCRIPT=' BEGIN { FS="|" } /^;/ { print ";"$0 } /.*\|.*/ && /^[^;]/ { #print $0 split($2, SRC, "/") #print "---" SRC[1] for(ITER in SRC) { print SRC[ITER] " /" $1 "/" } }' if [ "x${OUTPUT_SKK}" == "x" ] ; then if [ "x${OUTPUT_CDB}" == "x" ] ; then eecho "ERROR: No output files." exit 2 fi cat "$@" | awk "${AWK_CONVERT_SCRIPT}" | nkf -e | skkdic-p2cdb "${OUTPUT_CDB}" chmod 444 "${OUTPUT_CDB}" else if [ "x${OUTPUT_CDB}" == "x" ] ; then cat "$@" | awk "${AWK_CONVERT_SCRIPT}" | nkf -e | tee "${OUTPUT_SKK}" else cat "$@" | awk "${AWK_CONVERT_SCRIPT}" | nkf -e | tee "${OUTPUT_SKK}" | skkdic-p2cdb "${OUTPUT_CDB}" chmod 444 "${OUTPUT_CDB}" fi fi if [ "x${DONE_COMMAND}" != "x" ] ; then # never quote args of eval. eval ${DONE_COMMAND} fi