-- file: TFtoPLMain.mesa
-- Pascal-to-Mesa translator output, translated at September 14, 1985 3:12:44 pm PDT


DIRECTORY
  PascalBasic,
  PascalWizardFiles,
  TFtoPLPrivate,
  TFtoPLExternals;

TFtoPLMain: PROGRAM IMPORTS PascalBasic, PascalWizardFiles, TFtoPLPrivate, TFtoPLExternals EXPORTS  = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, TFtoPLPrivate, TFtoPLExternals;
 --2:-- --3:----:3----:90----6:--
TfmFile: ByteFile;
--:6----8:

Lf: PascalInteger[0..32767];

Lh: PascalInteger[0..32767];

Bc: PascalInteger[0..32767];

Ec: PascalInteger[0..32767];

Nw: PascalInteger[0..32767];

Nh: PascalInteger[0..32767];

Nd: PascalInteger[0..32767];

Ni: PascalInteger[0..32767];

Nl: PascalInteger[0..32767];

Nk: PascalInteger[0..32767];

Ne: PascalInteger[0..32767];

Np: PascalInteger[0..32767];
--:8----16:--
PlFile: Text;
--:16
--19:--Tfm: LONG POINTER TO ARRAY PascalInteger[-1000..20000] OF Byte ← PascalStaticZone.NEW[ARRAY PascalInteger[-1000..20000] OF Byte];
--:19----22:


CharBase: PascalInteger;

WidthBase: PascalInteger;

HeightBase: PascalInteger;

DepthBase: PascalInteger;

ItalicBase: PascalInteger;

LigKernBase: PascalInteger;

KernBase: PascalInteger;

ExtenBase: PascalInteger;

ParamBase: PascalInteger;
--:22----25:--
FontType: PascalInteger[0..2];
--:25
--27:--Ascii04: LONG POINTER TO PACKED ARRAY PascalInteger[1..32] OF PascalChar ← PascalStaticZone.NEW[PACKED ARRAY PascalInteger[1..32] OF PascalChar];
Ascii10: LONG POINTER TO PACKED ARRAY PascalInteger[1..32] OF PascalChar ← PascalStaticZone.NEW[PACKED ARRAY PascalInteger[1..32] OF PascalChar];
Ascii14: LONG POINTER TO PACKED ARRAY PascalInteger[1..32] OF PascalChar ← PascalStaticZone.NEW[PACKED ARRAY PascalInteger[1..32] OF PascalChar];

MblString: LONG POINTER TO PACKED ARRAY PascalInteger[1..3] OF PascalChar ← PascalStaticZone.NEW[PACKED ARRAY PascalInteger[1..3] OF PascalChar];
RiString: LONG POINTER TO PACKED ARRAY PascalInteger[1..3] OF PascalChar ← PascalStaticZone.NEW[PACKED ARRAY PascalInteger[1..3] OF PascalChar];
RceString: LONG POINTER TO PACKED ARRAY PascalInteger[1..3] OF PascalChar ← PascalStaticZone.NEW[PACKED ARRAY PascalInteger[1..3] OF PascalChar];
--:27----29:
Dig: LONG POINTER TO ARRAY PascalInteger[0..11] OF PascalInteger[0..9] ← PascalStaticZone.NEW[ARRAY PascalInteger[0..11] OF PascalInteger[0..9]];
--:29----32:--
Level: PascalInteger[0..5];
--:32----45:

CharsOnLine: PascalInteger[0..8];

Perfect: PascalBoolean;
--:45----47:--
I: PascalInteger[0..32767];

C: Byte;

R: Byte;


K: Index;
--:47----63:--LabelTable: LONG POINTER TO ARRAY PascalInteger[0..257] OF RECORD[Cc: Byte, Rr: PascalInteger[0..256]] ← PascalStaticZone.NEW[ARRAY PascalInteger[0..257] OF RECORD[Cc: Byte, Rr: PascalInteger[0..256]]];

LabelPtr: PascalInteger[0..256];

SortPtr: PascalInteger[0..256];
--:63----68:--
Active: PascalBoolean;
--:68----91:

Output: Text;
 TFtoPLRun: UnsafeCommandProc = BEGIN 
 TtyRewrite[@Output];Initialize[];
{IF  NOT Organize [] THEN  GOTO Label9999;DoSimpleThings[];--65:----66:
FOR i:INT    IN [ INT[Bc ].. INT[Ec ]] DO  C ← i; IF( Tfm↑[4*(CharBase+C)+2]MOD 4)=1  THEN BEGIN R←Tfm↑[4
*(CharBase+C)+3];IF  INT[R]>=Nl  THEN BEGIN BEGIN Perfect←FALSE;{PascalWriteLongString[file: @Output, item: " "]; PascalWriteLn[file: @Output]};
{PascalWriteLongString[file: @Output, item: "Ligature/kern"]; PascalWriteLongString[file: @Output, item: " index for character "]};PrintOctal[C];
{PascalWriteLongString[file: @Output, item: " is too large;"]; PascalWriteLn[file: @Output]};{PascalWriteLongString[file: @Output, item: "so I reset it to zero."]; PascalWriteLn[file: @Output]}; END;
Tfm↑[4*(CharBase+C)+2]←4*( Tfm↑[4*(CharBase+C)+2]/4)+0; END  ELSE--67:
BEGIN SortPtr←LabelPtr;
WHILE  INT[LabelTable↑[SortPtr].Rr]>R DO BEGIN LabelTable↑[SortPtr+1]←
LabelTable↑[SortPtr];SortPtr←SortPtr-1; END ENDLOOP ;
LabelTable↑[SortPtr+1].Cc←C;LabelTable↑[SortPtr+1].Rr←R;
LabelPtr←LabelPtr+1; END--:67--; END ENDLOOP;LabelTable↑[LabelPtr+1].Rr←256;
--:66--IF  INT[Nl]>0  THEN BEGIN Left[];PascalWriteLongString[file: @PlFile, item: "LIGTABLE"];OutLn[];--69:
Active←FALSE;SortPtr←1;FOR i:INT    IN [ INT[0 ].. INT[Nl-1 ]] DO  I ← i; --70:
WHILE I=LabelTable↑[SortPtr].Rr DO BEGIN IF  INT[Level]>1  THEN Right[];
Active←TRUE;Left[];PascalWriteLongString[file: @PlFile, item: "LABEL"];
OutChar[LabelTable↑[SortPtr].Cc];Right[];SortPtr←SortPtr+1; END--:70-- ENDLOOP ;
IF  NOT Active  THEN--71:--BEGIN Left[];
PascalWriteLongString[file: @PlFile, item: "COMMENT THIS PART OF THE PROGRAM IS NEVER USED!"];OutLn[];
Active←TRUE; END--:71--;--72:--BEGIN K←4*(LigKernBase+I);
IF  INT[Tfm↑[K+2]]>=128  THEN--73:
BEGIN IF(( INT[Tfm↑[K+1]]<Bc)OR ( INT[Tfm↑[K+1]]>Ec)OR (Tfm↑[4*(CharBase+Tfm↑[K+1])]=0))
 THEN BEGIN Perfect←FALSE;IF  INT[CharsOnLine]>0  THEN {PascalWriteLongString[file: @Output, item: " "]; PascalWriteLn[file: @Output]};
CharsOnLine←0;
{PascalWriteLongString[file: @Output, item: "Bad TFM file: "]; PascalWriteLongString[file: @Output, item: "Kern step for"]; PascalWriteLongString[file: @Output, item: " nonexistent character "]};
PrintOctal[Tfm↑[K+1]];{PascalWriteLongString[file: @Output, item: "."]; PascalWriteLn[file: @Output]}; END  ELSE BEGIN Left[];
PascalWriteLongString[file: @PlFile, item: "KRN"];OutChar[Tfm↑[K+1]];
IF  INT[Tfm↑[K+3]]>=Nk  THEN BEGIN BEGIN Perfect←FALSE;
IF  INT[CharsOnLine]>0  THEN {PascalWriteLongString[file: @Output, item: " "]; PascalWriteLn[file: @Output]};CharsOnLine←0;
{PascalWriteLongString[file: @Output, item: "Bad TFM file: "]; PascalWriteLongString[file: @Output, item: "Kern index too large."]; PascalWriteLn[file: @Output]}; END;
PascalWriteLongString[file: @PlFile, item: " R 0.0"]; END  ELSE OutFix[4*(KernBase+Tfm↑[K+3])];Right[];
 END; END--:73-- ELSE--74:
BEGIN IF(( INT[Tfm↑[K+1]]<Bc)OR ( INT[Tfm↑[K+1]]>Ec)OR (Tfm↑[4*(CharBase+Tfm↑[K+1])]=0))
 THEN BEGIN Perfect←FALSE;IF  INT[CharsOnLine]>0  THEN {PascalWriteLongString[file: @Output, item: " "]; PascalWriteLn[file: @Output]};
CharsOnLine←0;
{PascalWriteLongString[file: @Output, item: "Bad TFM file: "]; PascalWriteLongString[file: @Output, item: "Ligature step for"]; PascalWriteLongString[file: @Output, item: " nonexistent character "]};
PrintOctal[Tfm↑[K+1]];{PascalWriteLongString[file: @Output, item: "."]; PascalWriteLn[file: @Output]}; END;
IF(( INT[Tfm↑[K+3]]<Bc)OR ( INT[Tfm↑[K+3]]>Ec)OR (Tfm↑[4*(CharBase+Tfm↑[K+3])]=0)) THEN
BEGIN Perfect←FALSE;IF  INT[CharsOnLine]>0  THEN {PascalWriteLongString[file: @Output, item: " "]; PascalWriteLn[file: @Output]};
CharsOnLine←0;{PascalWriteLongString[file: @Output, item: "Bad TFM file: "]; PascalWriteLongString[file: @Output, item: "Ligature step produces the"]
; PascalWriteLongString[file: @Output, item: " nonexistent character "]};PrintOctal[Tfm↑[K+3]];{PascalWriteLongString[file: @Output, item: "."]; PascalWriteLn[file: @Output]};
 END  ELSE BEGIN Left[];PascalWriteLongString[file: @PlFile, item: "LIG"];OutChar[Tfm↑[K+1]];
OutChar[Tfm↑[K+3]];Right[]; END; END--:74--;
IF  INT[Tfm↑[K]]>=128  THEN BEGIN IF  INT[SortPtr]>0  THEN BEGIN 
PascalWriteLongString[file: @PlFile, item: "(STOP)"];OutLn[];IF  INT[Level]>1  THEN Right[]; END;Active←FALSE; END; END--:72--;
 ENDLOOP;IF Active  THEN BEGIN BEGIN Perfect←FALSE;
IF  INT[CharsOnLine]>0  THEN {PascalWriteLongString[file: @Output, item: " "]; PascalWriteLn[file: @Output]};CharsOnLine←0;
{PascalWriteLongString[file: @Output, item: "Bad TFM file: "]
; PascalWriteLongString[file: @Output, item: "No stop bit at the end of ligature/kern program."]; PascalWriteLn[file: @Output]}; END;
BEGIN PascalWriteLongString[file: @PlFile, item: "(STOP)"];OutLn[];IF  INT[Level]>1  THEN Right[]; END;
Tfm↑[4*(KernBase+0)-4]←Tfm↑[4*(KernBase+0)-4]+128; END--:69--;Right[];
 END--:65--;--75:
IF  INT[Ne]>0  THEN FOR i:INT    IN [ INT[0 ].. INT[Ne-1 ]] DO  C ← i; FOR i:INT    IN [ INT[0 ].. INT[3 ]] DO  R ← i;  K←4*(ExtenBase
+C)+R;
IF( INT[Tfm↑[K]]>0)OR (R=3) THEN BEGIN IF(( INT[Tfm↑[K]]<Bc)OR ( INT[Tfm↑[K]]>Ec)OR (Tfm↑[4*(
CharBase+Tfm↑[K])]=0)) THEN BEGIN BEGIN Perfect←FALSE;
IF  INT[CharsOnLine]>0  THEN {PascalWriteLongString[file: @Output, item: " "]; PascalWriteLn[file: @Output]};CharsOnLine←0;
{PascalWriteLongString[file: @Output, item: "Bad TFM file: "]; PascalWriteLongString[file: @Output, item: "Extensible recipe involves the"]
; PascalWriteLongString[file: @Output, item: " nonexistent character "]};PrintOctal[Tfm↑[K]];{PascalWriteLongString[file: @Output, item: "."]; PascalWriteLn[file: @Output]}; END;
IF  INT[R]<3  THEN Tfm↑[K]←0; END; END;--:75-- ENDLOOP ENDLOOP;DoCharacters[];{PascalWriteLongString[file: @Output, item: "."]; PascalWriteLn[file: @Output]};
IF Level#0  THEN {PascalWriteLongString[file: @Output, item: "This program isn't working!"]; PascalWriteLn[file: @Output]};
IF  NOT Perfect  THEN 
PascalWriteLongString[file: @PlFile, item: "(COMMENT THE TFM FILE WAS BAD, SO THE DATA HAS BEEN CHANGED!)"];
EXITS Label9999 => NULL};FileClose[@PlFile];ByteFileClose[@TfmFile];--:88
 END;

PascalRegister["TFtoPL", TFtoPLRun];

END.