#!/bin/sh
#
# this script extracts "afnx" fonts from Treo680 "Latin Locale Module.prc"
# converts them to text files for easy editing, and them packs them back
# in LatinLocaleModules_patched.pdb for uploading to Treo.
#
# it uses change_treo_system_font.pl (which should be enclosed)
# as well as fontconv from http://sourceforge.net/projects/palmfontconv/
#
# note: we use *_lores.tmp files as a workaround for a bug in fontconv
# which does not want to accept text version for lores font.
#
# note: if you have a lores-only device such as Treo600, you will need
# to modify script - lores afnx files do no contain both hires and lores
# fonts ("2a" fontconv type), but only lores ("1a"). So update script
# as needed for you.

###
# Primary use for this programs was to allow my treo680 to use Croatian letters
# without lowering system stability by using PalmOS hacks.
#
# I use change_treo_system_font.pl to modify fonts to show characters correctly
# and ac_fix.pl (from same author) to modify Alt keys to allow me to enter characters
# using standard Treo functionality (and also kill/modify annoying Auto Correct stuff)
#
# drop by to http://linux.voyager.hr/palmos/ to find both programs.
#
# Main problem was that Piloc, which is easy way to localize your treo is very unstable on 
# treo680 (from time to time starts entering wrong characters), and it also modifies behaviour
# and makes Treo less stable.
#
# So, I've made it - localized Treo680 to Croatian, WITHOUT any system hacks.
#

PRCFILE="Latin Locale Module.prc"
FONTCONV="./palmfontconv/fontconv"

rm -f $PRCFILE*.bin $PRCFILE*.txt $PRCFILE*.tmp
./change_treo_system_font.pl "$PRCFILE" parsepdb
for f in $PRCFILE_*.bin
do 
	$FONTCONV -l "${f}" t "${f}_lores.txt"
	$FONTCONV "${f}" T "${f}_hires.txt"
done

echo "File parsed. Edit and recombine NOW, and type 'exit' when finished to recombine"

# let user do the stuff...
zsh

echo "Starting the recombine process..."
for f in $PRCFILE_*.bin
do 
	$FONTCONV "${f}_lores.txt" La "${f}_lores.tmp"
	$FONTCONV "${f}_hires.txt" -i "${f}_lores.tmp" 2a "${f}"
done
./change_treo_system_font.pl "$PRCFILE" updatepdb
echo All done. Now install LatinLocaleModules_patched.pdb to your treo.

