c Name: cebuano.cct
c Author: Norbert Rennert
c Date: April 12, 2007
c Purpose: to massage the Cebuano dictionary file
c The logic is this:
c * If \et is present then it becomes \sr.
c * If \mr is present and it is different from \lx after stripping \lx
c of hyphens, then it becomes \sr.
c * If \bw is present:
c ** If the first parameter is "en":
c *** If \ge!= \lx then \sr = "en" + ge; else \sr = "en"
c ** else \sr = \bw
c The \sr field gets formatted as follows:
 c aba (native word: no \sr field)
c abaka [Tag] (Tagalog word borrowed as is)
c amatyur [Eng fi:amateur] (English word borrowed with change in sp)
c kasub-anan [ka-SUBO-anan] (derived word with the root not so obvious)

begin > 
use(main)
group(main)
'\lx ' > dup c output the \lx marker
	clear(ge,LxHyphen,english) c clear all flags
	store(BW,MR1,MR2,GE,LX,LX1,LX2) endstore c empty all stores
	store(LX1) c start storing LX1: is the first part of a hyphenated word
	use(findEndOfLXLine) c switch to the named group
	
'\et' > '\sr' c if you find the \et change it to \sr
'\mr ' > store(MR1) use(findEndOfMR1Line) c switch control to the named group
'\ge ' > set(ge) store(GE) use(findEndOfGELine) c switch control to the named group
'\bw ' > store(BW) use(findEndOfBWLine) c switch control to the named group

group(findEndOfLXLine)
'-' > endstore set(LxHyphen) store(LX2) c LX2 is the second part of a hyphenated word
nl > endstore c stop storing when you reach the new line
	if(LxHyphen) out(LX1) '-' out(LX2) c output the lx1 part before the LXhyphen; add the LXhyphen; output the second part of the lx
		store(LX) outs(LX1,LX2) endstore c store LX1 and LX2 into a store called LX for later comparison (this time without the LXhyphen)
	endif 
	ifn(LxHyphen) out(LX1,LX2) c if the lx had no LXhyphen, output the LX1 and LX2 stores (LX2 should be empty, but it doesn't hurt to output it anyway)
		store(LX) outs(LX1,LX2) endstore c store LX1 and LX2 into a store called LX for later comparison
	endif
	dup c output the new line
	use(main) c switch control to the named group
	
group(findEndOfMR1Line) c first pass through the MR field to store everything as is (with or without hyphens)
nl > endstore 
	' ' out(MR1)
	use(Backup)

group(Backup)
'' > back(1)
' ' > store(MR2) 
	use(findEndOfMR2Line) c begin storing MR2: the unhyphenated version of the \mr field

group(findEndOfMR2Line)
'-' > ''
nl > endstore
	ifeq(MR2) cont(LX) ''  c if the contents of MR2 (the unhyphenated version) is equal to the contents of LX (the unhyphenated version) then output nothing
		else '\mr ' out(MR1) nl c otherwise output a \mr and then the contents of MR
	endif
	dup c output the new line
	use(main) c switch control to the named group

group(findEndOfGELine)
nl > endstore use(main) c switch control to the named group (note: the new line doesn't get output)

group(findEndOfBWLine)
'en' > set(english)
nl > endstore
	if(english) c start outer loop
		begin c start inner loop if the english flag is set
			ifneq(GE) cont(LX) '\sr en fi:' out(GE)
			else '\sr en'
			endif
		end c end inner loop
	else
		'\sr ' out(BW)
	endif
	dup use(main) c switch control to the named group