#!/bin/csh -f
#
# 			lx2cm  rev 1.0
#
#		Converts HP95LX Appointments
#		to OpenWindows Calendar Manager
#		format.  Requires OWv3.
#
#		By Todd Bernhard, Product Manager
#		Sun Microsystems Computer Corporation
#		415-336-7047  Todd.Bernhard@Sun.COM
#
#
# 

set noglob
set noclobber

clear
echo ""
echo "		lx2cm rev 1.0"
echo ""
echo " HP95LX Appointment Book to"
echo " OpenWindows 3.0 Calendar Manager"
echo ""
echo " Transfer Utility developed by Todd Bernhard,"
echo " Sun Microsystems Computer Corporation"
echo " 415-336-7047    Todd.Bernhard@Sun.COM"
echo ""
echo " This is Freeware...feel free to distribute, in"
echo " the interest of Open Systems.  Modifications and"
echo " enhancements are welcome."
echo ""
echo " Do you want instructions, Y/N?"
set inst = $<
switch ($inst)
 case [yY] :
  echo ""
  echo " This program will allow you to transfer appointments"
  echo " from the HP95LX scheduler to a Sun workstation, or"
  echo " compatible, running OpenWindows 3.0."
  echo ""
  echo " To use this utility, follow these directions on the HP95LX."
  echo ""
  echo "	1) Within the Appointment Book program"
  echo "		- Choose MENU Print File Appts Without-Notes"
  echo "		- Enter Start date (e.g. 01/11/92)"
  echo "		- Enter End date (e.g. 02/11/92)"
  echo "		- Choose Many-Days-Per-Page"
  echo "		- Enter filename to store appointments (e.g. ap.txt)"
  echo ""
  echo "	2) Using your favorite communications program,"
  echo "	   transfer the appointment file you just created"
  echo "	   (e.g. ap.txt) to the Sun workstation."
  echo ""
  echo "	3) Run this program, logged in as yourself.  The"
  echo "	   appointments will automatically be entered in"
  echo "	   your Calendar Manager."
  echo ""
  echo ""
endsw

if ($#argv == 0) then
 echo "Please enter the name of the file containing the HP95LX appointments."
 set fname = $<
else
 set fname = $argv
endif

if (! -f $fname) then
 echo "No such file...sorry."
 echo ""
 exit 1
endif

dos2unix $fname /tmp/ap$$

set hpappt = /tmp/ap$$
@ linectr = 0
set nl = `wc -l $hpappt`
@ numlines = $nl[1]

while ($linectr != $numlines)
 @ linectr++
 set junkline = `head -$linectr $hpappt | tail -1`
 set appline = `echo $junkline`
 switch ($#appline)
  case [01] : 
  	breaksw
  case 2 :
  	set appdate = $appline[2]
  	breaksw
  default:
   cm_insert -d $appdate -s $appline[1]$appline[2] -w $appline 
   breaksw
 endsw
end
