;
; COPYRIGHT 1980,1987 CONVERGENT TECHNOLOGIES, INC.
; ALL RIGHTS RESERVED
;
; THIS PROGRAM IS FURNISHED UNDER A LICENSE RESTRICTING ITS USE
; SOLELY FOR THE OPERATION OF A DESIGNATED COMPUTER FOR A
; PARTICULAR PURPOSE, AND MAY NOT BE  COPIED OR OTHERWISE USED
; WITHOUT THE PRIOR WRITTEN CONSENT OF CONVERGENT  TECHNOLOGIES,
; INC.  TITLE TO AND OWNERSHIP OF THE PROGRAM, INCLUDING ITS
; SOURCE CODE, SHALL AT ALL TIMES REMAIN IN CONVERGENT TECHNOLOGIES.
;


*DEFINE (InitDiacriticalTables) (
	SET(cEntries,0)
	DEFINE (String1) ()
	DEFINE (String2) ()
	)

*DEFINE (DiacriticalSet(bDiacriticalKey,bFollowingKey,bResultantKey)) (
	DEFINE (tmpString) (String1)
	DEFINE (String1) (tmpString
				DB	bDiacriticalKey,bFollowingKey)
	DEFINE (tmpString) (String2)
	DEFINE (String2) (tmpString
				DB	bResultantKey)
	SET(cEntries, cEntries+1)
	)

*DEFINE (EndDiacriticalTables) (
	cDiacriticalPairs	DW	cEntries
				String1
				String2
	)

Set(cbTable,0)
Set(cTable,0)


STACK segment word stack 'STACK'
STACK ends


HdrSeg SEGMENT PUBLIC 'const'
wSignature			DB	'T', 'N'			
cbFile 			DW 0
cStruct			DW 0
orgID			DW 0
orgOStruct			DW 0
fill			DW 0,0,0
HdrSeg ENDS

sHdrSeq EQU 10h

IdSeg SEGMENT WORD PUBLIC 'const'
rgId	  LABEL WORD
IdSeg ENDS

oStructSeg SEGMENT WORD PUBLIC 'const'
rgoStruct  LABEL WORD
oStructSeg ENDS

rgbStructSeg SEGMENT WORD PUBLIC 'const'
rgbStruct  LABEL BYTE
rgbStructSeg ENDS

TGroup GROUP HdrSeg, IdSeg, oStructSeg, rgbStructSeg, endNlsTable


*DEFINE (DefTableString(name, id, string)) LOCAL rgbStart (
x1Out(name (id) ... )
DEFINE (arg) (string)
IdSeg SEGMENT
DW id
IdSeg ENDS
rgbStructSeg SEGMENT
rgbStart LABEL BYTE
WHILE (LEN(arg) GT 0) (MATCH (head, arg) (arg)
DB head
)
rgbStructSeg ENDS
oStructSeg SEGMENT
DW OFFSET TGroup:rgbStart
oStructSeg ENDS
Set(cTable, cTable+1)
Set(cbTable, cbTable+len(string))
x1Out(done.nl)
)


*DEFINE (DefTablesbString(name, id, sbString)) LOCAL tmp0 tmp1 (
x1Out(name (id) ... )
IdSeg SEGMENT
DW id
IdSeg ENDS
rgbStructSeg SEGMENT
tmp0 LABEL BYTE
DB 0
IF(NES(sbString,''))THEN(	DB sbString)FI
tmp1 LABEL BYTE
ORG OFFSET tmp0
DB tmp1tmp01
rgbStructSeg ENDS
oStructSeg SEGMENT
DW OFFSET TGroup:tmp0
oStructSeg ENDS
Set(cTable, cTable+1)
Set(cbTable, cbTable+len(sbString)+1)
x1Out(done.nl)
)


*DEFINE (SbString(Str)) LOCAL tmp0 tmp1 (
rgbStructSeg SEGMENT
tmp0 LABEL BYTE
DB 0
IF(NES(str,''))THEN(	DB str)FI
tmp1 LABEL BYTE
ORG OFFSET tmp0
DB tmp1tmp01
ORG OFFSET tmp1
rgbStructSeg ENDS
)


*DEFINE (DefTableData(name, id, data)) LOCAL rgb0 rgb1 (
x1Out(name (id) ... )
DEFINE (arg) (data)
IdSeg SEGMENT
DW id
IdSeg ENDS
rgbStructSeg SEGMENT
rgb0 LABEL BYTE
data
rgb1 LABEL BYTE
rgbStructSeg ENDS
oStructSeg SEGMENT
DW OFFSET TGroup:rgb0
oStructSeg ENDS
Set(cTable, cTable+1)
Set(cbTable, cbTable+(rgb1rgb0))
x1Out(done.nl)
)



*DEFINE (TableEnd)(
EndNlsTable segment public 'const'
TheEnd label byte
EndNlsTable ends

HdrSeg SEGMENT PUBLIC 'const'
ORG OFFSET cbFile
DW offset TGroup:TheEnd 
ORG OFFSET cStruct
DW cTable 
ORG OFFSET orgId
DW OFFSET TGRoup:rgId
ORG OFFSET orgoStruct
DW OFFSET TGRoup:rgoStruct
HdrSeg ENDS
)

*DEFINE (TableInit)(
' 'x1Out(Creating NLS tables:nl)'
)

*DEFINE(xOut(str))(IF (PASS1 EQ 1) THEN (out(str)) FI)
*DEFINE(x2Out(str))(IF (PASS2 EQ 1) THEN (out(str)) FI)
*DEFINE(x1Out(str))(out(str))
DEFINE(nl)(
)


;StartKeycapDefines Macro
;Set up the data space for the Keycap Template arrays.  The 
;pointer array of these templates is called rgsbTemplates
*DEFINE (StartKeycapDefines)(

;	rgKeycap is an array of offsets which describe the beginning 
;	of each of the structures in the Nls Keycap section of the NLS 
;	tables.
public rgKeyCap

rgKeyCap					LABEL		BYTE
					
wKeyCapSig					DW		'KC' '               Name table signature

wRevLevel					DW		0 '                  Revision level 

cKeyCaps					DW		0 '                  Number of keycaps

orgosbKeyCap					DW		0 '                  offset to keycap list


SET(NoKeyCaps, 1)
sbKeyCaps label byte
)
; KeycapEntry Macro
; Create a table entry for the template form provided.  Takes a 
; name and string value:

; DefineKeycapEntry(Help_00, HELP)

; This creates an entry called sbHelp_00 with the provided
; String, and adds it sequentially to the data structures.

*DEFINE (DefineKeyCapEntry(NameKeyCap, String))(
sbNoKeyCaps LABEL BYTE						' SB starts here

	DB	len(String)				' String length

	DB	'String'				' String text

	DB	0				' Null terminator for C etc

SET(NoKeyCaps, NoKeyCaps+1)
)
;EndKeycapDefines Macro
;Wraps up the data space for the Keycap String arrays and 
;other structures.  
*DEFINE (EndKeycapDefines)(

; Describe the available tables by rgTables offset
SET (iKeyCap, 1)
rgosbKeyCap LABEL BYTE

WHILE (iKeyCap LT NoKeyCaps) (
	DW		(OFFSET sbiKeyCap)  (OFFSET rgKeyCap)
	SET (iKeyCap, iKeyCap + 1)
)

EndKeyCapData label byte

ORG OFFSET cKeyCaps
	DW		NoKeyCaps  1
ORG OFFSET orgosbKeyCap
	DW		(OFFSET rgosbKeyCap)  (OFFSET rgKeyCap)
ORG OFFSET EndKeyCapData
)




;
; StartNameDefines Macro     Set up the data space for the Date Time
;                          Template arrays.  The pointer array of
;                          These templates is called rgsbTemplates
;

*DEFINE (StartNameDefines)(

public NameStruct

SET(TableNo, 1) 
SET(Started, 0) 
SET(StringMax, 0FFH) 
'
'
'
'
'                    N L S   N A M E   S T R U C T U R E
'
' NameStruct is a structure of offsets and counts which describe the 
' structures in the Nls Name section of the NLS tables.
'
'
'

NameStruct label byte
qNameSignature   DW   'NT'
wNameRevLevel    DW   0
cTables          DW   0
orgoTables       DW   0
)


;
; NameEntry Macro     Create a table entry for the template form
;                       provided.  Takes a name and string value:
;
;    DefineNameEntry(FirstMonth, january)
;
; This creates an entry called FirstMonth with the provided String, and 
; adds it sequentially to the data structures.
;

; Define the string
*DEFINE (DefineNameEntry(NameString, String))(

IF ((StringNo LT StringMax) AND (Started EQ 1)) THEN (
	sbStringNoTableNo label byte
	db	len(String) 
	db	'String' 
	db 0 
	SET (StringNo, StringNo+1)
) ELSE (
	IF (StringNo EQ StringMax) THEN (
		OUT (DateString: StringNo;  Table: TableNo;  Too many strings in table, first table contained StringMax strings.
)
	) ELSE (
		OUT(Table number TableNo must Begin before name strings can be defined
)
	) FI
) FI
)




;
;  Start Table Macro     Begin a new list of date names 
;


*DEFINE (StartNameTable)(
'
' remember the start of this list of string offsets
'
IF (Started EQ 1) THEN (
	OUT(Table number TableNo must End before another can begin
)
) ELSE (
	SET (StringNo, 1)
'
'	  Set the We are in a table flag, and warn user if last table not closed
	SET(Started, 1)
) FI
)



;
;  End Name Table Macro     Close up a list of strings
;

*DEFINE (EndNameTable)(
'
'
'
' Warn user that we are closing a tabel that was not opened up
IF (Started EQ 0) THEN (
	OUT(Table number TableNo must Begin before it can end
)
) ELSE (
	IF (StringMax EQ 0FFH) THEN (
		SET (StringMax, StringNo)
	) FI
	IF (StringNo LT StringMax) THEN (
		OUT (Table: TableNo;  Table must contain StringMax strings, this table contains only StringNo strings
)
	) ELSE (
		SET(TableNo, TableNo+1)
		SET(Started, 0)
	) FI
) FI
)



;
; EndNameDefines Macro     Wraps up the data space for the Name
;                        String arrays and other structures.  
;

*DEFINE (EndNameDefines)(
'
IF (Started EQ 1) THEN (
	OUT(Table number TableNo must End before name definitions can End
)
) ELSE (
	SET (iTable, 1)
'
	WHILE (iTable LT TableNo) (
		TableiTable label byte

		Set (iName, 1) 

		WHILE (iName LT StringMax) (
			DW	(OFFSET sbiNameiTable)  (OFFSET NameStruct)
			SET (iName, iName+1)
		)
		SET (iTable, iTable+1)
		SET (iName, 1)
	)
'
	SET (iTable, 1)
	rgoTables label byte
	WHILE (iTable LT TableNo) (
		DW   StringMax1
		DW	(OFFSET TableiTable)  (OFFSET NameStruct)
		SET (iTable, iTable + 1)
	)

EndNameData Label byte

'	
'
'	
'
' Describe the available tables by rgTables offset
'
	ORG OFFSET cTables
	DW   TableNo1
	ORG OFFSET orgoTables
	DW   (OFFSET rgoTables)  (OFFSET NameStruct)
	ORG OFFSET EndNameData
'
'
) FI
)





;
; StartDateDefines Macro     Set up the data space for the Date Time
;                          Template arrays.  The pointer array of
;                          These templates is called rgsbTemplates
;

*DEFINE (StartDateDefines)(
'
public DateStruct

'
'
'                  N L S   D A T E   S T R U C T U R E
' DateStruct is an structure of offsets and counts which describe the 
' structures in the Nls Date section of the NLS tables.
'
'

DateStruct label byte
qDateSignature  dw   'DT'
wDateRevLevel   dw   0
cCtTemplates    dw   0
cOemTemplates   dw   0
orgoTemplates   dw   0
'
cEscs           dw   0
orgCmds         dw   0
'
'
SET(NumSbs, 0)
SET(NumCtTemps, 0)
SET(NumOemTemps, 0)
'
SET(NumEscs, 0)
'
SET(BuildPhase, 1)
'
'
rgCmds label byte
'
)


;
; DateEscapeDefine Macro     Defines the character to be used for each
;                              of the escape sequences (attributes) in the
;                              NLS Date templates.    
;


*DEFINE (DateEscapeDefine(CommandName, 'bLower', 'bUpper'))(
'
IF (BuildPhase EQ 1) THEN (
db  	'bLower'
db  'bUpper'
'
SET(NumEscs, NumEscs+1)
'
) ELSE (
	OUT(Command: CommandName;  Command characters must be defined before other NLS Date information.
)
) FI
)








;
; TemplateEntry Macro     Create a table entry for the template form
;                           provided.  Takes a name and string value:
;
;    DefineTemplateEntry(LongDayDate, W*w N*n *d, *y)
;
; This creates an entry called LongDayDate of the provided format, and 
; adds it sequentially to the data structures.
;

*DEFINE (DefineTemplateEntry(TemplateName, TemplateString))(
'
'Transitioning from command char definition, disallow further command defines
IF (BuildPhase EQ 1) THEN (
	SET (BuildPhase, 2)           
) FI
'
IF ((BuildPhase EQ 2) OR (BuildPhase EQ 3)) THEN (
	sbTemplateNumSbs label byte 
	db	len(TemplateString) 
	db	'TemplateString' 
	db 0 
'
	SET(NumSbs, NumSbs+1)
'
	IF (BuildPhase EQ 2) THEN (
		SET(NumCtTemps, NumCtTemps+1)
	) ELSE (
		SET(NumOemTemps, NumOemTemps+1)
	) FI
'
) ELSE (
	OUT(Template: TemplateName;  Templates must be defined immediately after command characters
)
) FI
'
)





;
; EndStdDateDefines Macro     Wraps up the data space for the Date Time
;                           Template arrays and other structures.  The 
;                           number of templates is put in in cTemplates,
;                           which is referenced by its offset, as is the
;                           array of escapes.
;

*DEFINE (EndStdDateDefines)(
IF (BuildPhase EQ 2) THEN (
	SET (BuildPhase, 3)
) ELSE (
	OUT (Command characters and Standard templates must be defined before OEM templates
)
) FI
)


;
; EndOemDateDefines Macro     Wraps up the data space for the Date Time
;                           Template arrays and other structures.  The 
;                           number of templates is put in in cTemplates,
;                           which is referenced by its offset, as is the
;                           array of escapes.
;
'
*DEFINE (EndOemDateDefines)(
'
IF (BuildPhase EQ 3) THEN (
'
'	Disallow any further definitions
	SET (BuildPhase, 4)
'
	rgosbTemplates LABEL BYTE
'
	SET (iosb, 0)
'
	WHILE (iosb LT NumSbs) (
		DW	(OFFSET sbTemplateiosb)  (OFFSET DateStruct)
		SET (iosb, iosb+1)
	)
'
EndDateData  label byte

	ORG OFFSET cCtTemplates
	DW   NumCtTemps
	ORG OFFSET cOemTemplates
	DW   NumOemTemps
	ORG OFFSET orgoTemplates
	DW	(OFFSET rgosbTemplates)  (OFFSET DateStruct)
	ORG OFFSET cEscs
	DW	 NumEscs
	ORG OFFSET orgCmds
	DW  (OFFSET rgCmds)  (OFFSET DateStruct)
	ORG OFFSET EndDateData
) ELSE (
	OUT (Error;  Command character, Default template, and OEM template definition areas must be present
)
) FI
)leNo must Begin