#!/bin/sh
# Copyright 1992 NEC Corporation, Tokyo, Japan.
#
# Permission to use, copy, modify, distribute and sell this software
# and its documentation for any purpose is hereby granted without
# fee, provided that the above copyright notice appear in all copies
# and that both that copyright notice and this permission notice
# appear in supporting documentation, and that the name of NEC
# Corporation not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.  NEC Corporation makes no representations about the
# suitability of this software for any purpose.  It is provided 
# "as is" without express or implied warranty.
#
# NEC CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN 
# NO EVENT SHALL NEC CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 
# OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 
# PERFORMANCE OF THIS SOFTWARE. 
#
# $Id: mkromdic.cpp,v 1.2 2003/06/28 19:36:48 aida_s Exp $





























































































































































































































































































PATH=/usr/pkg/bin:$PATH:/bin:/usr/bin:/etc:/usr/etc:/usr/nec/bin:/usr/ucb
export PATH

if [ $# -eq 0 ]; then
  echo "usage: mkromdic [...options] <file name>"
  exit 1
fi

while [ -n "$2" ]
do
	case $1 in
	  "-m")  flag_m="-m" ;;
	  "-n")  flag_n="-n" ;;
          *)     args="$args $1" 
        esac 
	shift
done

if [ ! -r $1 ]; then
  echo "mkromdic: cannot open $1"
  exit 1
fi			

if [ "OPT$flag_m" = "OPT-m" -a "OPT$flag_n" = "OPT-n" ]; then
  echo "mkromdic: option error -m -n"
  exit 1 
fi 

if [ "OPT$flag_n" = "OPT-n" ]; then
  echo "mkromdic: '-n' obsolete option.  It is no longer supported."
  exit 1 
fi 

INFILE=$1

OUTFILE=`basename $1`
OUTFILE=`echo $OUTFILE |  awk -F. '{printf "%s",$1; for(i=2; i<NF; i++) printf ".%s",$i}'`

KPDIC="kpdic $flag_m"
OUTFILE=$OUTFILE.cbp

set x cpp -traditional
if [ -x $2 ]; then
	echo "forcpp -7 < $INFILE |" cpp -traditional "$args |forcpp -8 | $KPDIC > $OUTFILE"
	forcpp -7 < $INFILE | cpp -traditional $args |forcpp -8 | $KPDIC > $OUTFILE
else
	echo "Cannot use cpp !!"
	echo "$KPDIC  < $INFILE > $OUTFILE"
	$KPDIC  < $INFILE > $OUTFILE
fi
