
  {declar}

 (* *)
 (*  begin  *)
			(*     g     14:10 26.10.2002   -25     *)

		{     =====  Irie Pascal  =====     }

		{     =====  compiler:  Ipw-100.exe  =====     }


 (*
		GB - Simplified Chinese Characters

		Frequency of characters, fonetics

                Text CN to xx.txt, result in xxxxx.txt

		Tables 161-254 x 161-254:   tab_97.txt, GB_a.txt

 *)


	{     Created by Severin Jelinek, Vsetin, Czech Republic     }

		{     E-mail:   sychrv2yahoo.com     }

		(*     chin_g     *)

	(* @@@@@@@@@@@@  add & set chars, create tabs, fonetics  @@@@@@@@@@@@ *)


 (*     cn2.p        *)
 (*     13.10.1999     *)


	(*     tx_orgA		end_txtA	all		     *)
	(*     tx_org		end_txt		non-GB  "="	     *)
	(*     tx_2		end_txt2	0-9, tab, space  "."     *)
	(*     tx_row		end_txt2	N, L  ".", "."	     *)

	(*     used		end_used     *)
	(*     used_fr		end_uf2     *)

	(*

	append   O=.,:;?""''<>
*
O	
=	
.	
,	
:	
;	
?	
"	
"	
'	
'	
<	
>	

	*)


 program chin_g(output, in1, tabchinc, out);

 const
   len_txt = 40000; 				{ 40000 }

   ch161 = '';  ch254 = '';  ch253 = '';

   eq1 = '';  eq2 = '';			{ "="   eq1, eq2   }
   per1 = '';  per2 = '';			{ "."   per1, per2   }
   apo1 = "";  apo2 = "";			{ "'"   apo1, apo2   }
   gt1 = "";  gt2 = "";			{ ">"   gt1, gt2   }


						{ "="   eq1, eq2   }
						{ "."   per1, per2   }
						{ "'"   apo1, apo2   }
						{ ">"   gt1, gt2   }


 type
   ch_file = file of char;
   txt = array[1..len_txt] of char;
   tab_cn = array[ch161..ch254, ch161..ch254] of char;

	tab_fon = array[ch161..ch254, ch161..ch254] of string;

 var
   in1, tabchinc, out : ch_file;
					(* input file, table, output file *)
   tx_org, tx_orgA, tx_2, tx_row, used, used_fr, used_fr2 : txt;

   GB_list : txt;

   freq_ch, zero_level : tab_cn;

	fonetics : tab_fon;

   end_txt, end_txtA, end_txt2, end_used, end_uf2 : integer;
   frequent, total : integer;
   info, info2, rem_1, s1, s2 : string;
   base, choice, zero : char;
   GB, Big5, GB_Big5 : Boolean;


		NL, temp, syllable : string;


  {declar}

  {proced}


{WWWWWWWWWW}

 	procedure freq_tab(var f : ch_file);
	var
		j : integer;  c, ci, cj, N, L : char;

	begin

		N := chr(13);  L := chr(10);

		write(f,N,L);
							(*  row  *)

		for  c := ch161 to ch254 do write(f, c);

		write(f,N,L);
							(*  table  *)

		j := 0;
		for  ci := ch161 to ch254 do
		for  cj := ch161 to ch254 do begin



			if choice = 'f' then begin

			temp := fonetics[ci,cj];  c := temp[1];

			end

			else 


			c := freq_ch[ci,cj];

			if j mod 94 = 0 then write(f, N, L);

			inc(j);    { if choice = 'f' then c := '.'; }

			write(f, c);
		end;

		write(f,N,L);

	end;

{WWWWWWWWWW}

 	procedure freq_tab2(var f : ch_file);
	var
		j : integer;  c, ci, cj, N, L : char;

	begin

		N := chr(13);  L := chr(10);

		write(f,N,L);
							(*  row  *)

		for  c := ch161 to ch254 do write(f, c);

		write(f,N,L);
							(*  table  *)

		j := 0;
		for  ci := ch161 to ch254 do
		for  cj := ch161 to ch254 do begin

		{ c := freq_ch[ci,cj]; }

		if j mod 94 = 0 then write(f, N, L);

			inc(j);

			write(f, base);		{ info[2] }

		end;

		write(f,N,L);

	end;





{WWWWWWWWWW}







 	procedure test_tab(var f : ch_file);
	var
		i : integer;  c, c1, c2, N, L : char;

	begin

		N := chr(13);  L := chr(10);

						(*  char: 180 to 189  *)
						(*  char: 180 to 189  *)

 write(f,N,L,' ',' ',' ');
	for i := 180 to 189 do begin

		c1 := chr(i);  c2 := chr(180);
		c := freq_ch[c1, c2];
		write(f, c, ' ');
	end;
 write(f,N,L);

 write(f,N,L,' ',' ',' ');
	for i := 180 to 189 do begin

		c1 := chr(i);  c2 := chr(180);
		write(f, c1, c2, ' ');
		freq_ch[c1, c2] := chr(i);

		freq_ch[c1, chr(ord(c2)+3)] := chr(i);
		freq_ch[c1, chr(ord(c2)+5)] := chr(i);
		freq_ch[c1, chr(ord(c2)+7)] := chr(i);
		freq_ch[c1, chr(ord(c2)+8)] := chr(i);
		freq_ch[c1, chr(ord(c2)-5)] := chr(i);
		freq_ch[c1, chr(ord(c2)-8)] := '';
		freq_ch[c1, chr(ord(c2)-9)] := '';
		freq_ch[c1, chr(ord(c2)-10)] := '';
		freq_ch[c1, chr(ord(c2)-11)] := '';
		freq_ch[c1, chr(ord(c2)-12)] := '';
	end;
 write(N,L);write(f,N,L);

	end;


{WWWWWWWWWW}

 	procedure wrNL(var f : ch_file);
	var
		s : string;  i : integer;  N, L, sp : char;

	begin
		n := chr(13);  L := chr(10);  sp := ' ';

		s := rem_1;
		write(f, N, L, sp, sp);
		for i := 1 to length(s) do begin
			write(f, s[i]);
			if i mod 50 = 0 then write(f, N, L);
		end;
		write(f, N, L);
	end;


{WWWWWWWWWW}

 	procedure wrTnl(var f : ch_file; new_line : Boolean);
	var
		s : string;  i : integer;  N, L, sp : char;

	begin
		N := chr(13);  L:= chr(10);  sp := ' ';
		s := rem_1;
		if new_line then begin
		write(f, N, L); write(f, N, L);
		for i := 1 to 5 do write(f, sp);
		end;
		for i := 1 to length(s) do begin
			write(f, s[i]);
			if i mod 50 = 0 then write(f, N, L);
		end;
		if new_line then begin
		write(f, N, L); write(f, N, L);
		end;
	end;



{WWWWWWWWWW}



 	procedure wrTnlN(var f : ch_file; new_line : Boolean; number : integer);
	var
		s : string;  i : integer;  N, L, sp : char;

	begin
		N := chr(13);  L:= chr(10);  sp := ' ';
		s := rem_1;
		if new_line then begin
		write(f, N, L); write(f, N, L);
		for i := 1 to 5 do write(f, sp);
		end;
		for i := 1 to length(s) do begin
			write(f, s[i]);

			if number <> 0 then

				if i mod number = 0 then write(f, N, L);
		end;
		if new_line then begin
		write(f, N, L); write(f, N, L);
		end;
	end;




{WWWWWWWWWW}

  {proced}



  {code}



{WWWWWWWWWW}


 


			(*     g     9:37 23.10.2002   -25     *)
 (*  begin  *)
 (*   *)

 (* *)
 (*  main  *)



						{#########}
						{#########}
						{#########}


                                       (* text in *)


   procedure Code(var f1, f2 : ch_file);


   label abc;


   var
      i, i2, j, k, x1, x2 : integer;
      c, c1, c2, N, L, CR, LF, TB : char;

	new_fon : string;

   begin
      N := chr(13);  L := chr(10);

      c2 := '9';
      CR := N;  LF := L;  NL := CR + LF;  TB := chr(9);

	s1 := '';  s2 := '';
	x1 := 0;  x2 := 0;




		rem_1 := '                  # # # # # ';  wrTnl(out, true);
		rem_1 := '       C O D E     ';  wrTnl(out, true);



						(*  ver  *)
						(*  ver  *)



	rem_1 := '                  ==========';  wrTnl(out, true);
	rem_1 := '          ver:  g     26.10.2002      ';
							wrTnl(out, true);


							{  table info  }



	rem_1 := info;  wrTnlN(out, true, 0);



	rem_1 := '                  ========== ';  wrTnl(out, true);



	rem_1 := '   tx_org  240       text in                     ';
							wrNL(out); {@@@@@}



 write(f2,N,L,' ');
							{ space }
	for i := 1 to len_txt do begin
		c := chr(240);				{  240 }
		tx_org[i] := c;
		tx_orgA[i] := c;
				{write(f2,c); ==============}
	end;

 write(f2,N,L,' ');




							{ tx_org }

		                       			{ text in }

				{ GB:   exclude letters  "="       eq1,eq2 }


	i := 0;  j := 0;
	while not eof(f1) do
	begin
		inc(i);  inc(j);  read(f1, c);

						{ exclude non-GB, '=' eq1, eq2 }
		if GB then
			if ((c > ' ') and (c < ch161)) then begin

				tx_org[i] := eq1;
				tx_org[i + 1] := eq2;
				inc(i);
			end

			else  tx_org[i] := c;


		tx_orgA[j] := c;


				{write(f2,c); ==============}

		end_txt := i;  end_txtA := j;
							{ text out }
	end;  

 write(f2,N,L,' ');



					{ ------------ }




					{@@@@@@@@@@ X O }

		if (choice = 'x') or (choice = 'o') then begin




		rem_1 := '       tx_orgA   >>>   ';  wrTnl(out, true);

							{ tx_orgA }
	for i := 1 to end_txtA do begin
		c := tx_orgA[i];
					{@@@@@@@@@@}
		write(f2,c);			{////////////////}

		{ if i mod 50 = 0 then write(f2,N,L);	50 	# # # # # }

					{@@@@@@@@@@}
	end;

 write(f2,N,L,' ');






						(*     ortginal table     *)

						{ frequency out }
 write(f2,N,L);

	rem_1 := '          first original frequncy table out       ';
							wrNL(out); {@@@@@}

				(*  test Y/N  @@@@@  *)

			if choice  = 'x' then begin

	rem_1 := '          testing                                 ';
							wrNL(out); {@@@@@}

						(*     table test    *)

				test_tab(out); 		{==============}

			end;

				(*  test Y/N  @@@@@  *)



						(*  frequency table  *)

			freq_tab(out);    {   +++++++++     }


						(*  txt length ////////\\\\\ *)

		end;

					{@@@@@@@@@@ X O }







                              			(* characters in *)


		rem_1 := '       tx_orgA   >>>   ';  wrTnl(out, true);


						(* characters, tx_orgA *)

 write(f2,N,L,' ');


	for i := 1 to end_txtA do begin
		c := tx_orgA[i];

		write(f2,c);			{////////////////}

		{ if i mod 50 = 0 then write(f2,N,L);	50 	# # # # # }

	end;




							{ space }

	for i := 1 to len_txt do begin
		c := '';  
		tx_2[i] := c;
				{write(f2,c); ==============}
	end;





		rem_1 := '       tx_2   >>>   ';  wrTnl(out, true);


						{ "="   eq1, eq2   }
						{ "."   per1, per2   }
						{ "'"   apo1, apo2   }
						{ ">"   gt1, gt2   }

	
	{ exclude numbers, tabulators and spaces    "'"   apo1, apo2   }


	i := 0;  j := 0;

	while i < end_txt - 1 do begin

		inc(i);  inc(j);
		c := tx_org[i];
		tx_2[j] := c;

		if ((c >= '0') and (c <= '9') or (c = ' ') or (c = chr(9))) then
		begin
			tx_2[j] := apo1;
			tx_2[j + 1] := apo2;
			inc(j);	
		end;



		end_txt2 := j;


		write(f2,c);			{////////////////}

		{ if i mod 50 = 0 then write(f2,N,L);	 50 	# # # # # }

	end;


 write(f2,N,L,' ');

		rem_1 := '       tx_row   >>>   ';  wrTnl(out, true);



						{ tx_row   no new lines}

							{ space }
	for i := 1 to len_txt do begin
		c := chr(250);				{  250 }
		tx_row[i] := c;
				{write(f2,c); ==============}
	end;



 write(f2,N,L,' ');


						{ "="   eq1, eq2   }
						{ "."   per1, per2   }
						{ "'"   apo1, apo2   }
						{ ">"   gt1, gt2   }


			{ exclude new lines    ">"   gt1, gt2   }


	i := 0;

	while i < end_txt2 - 1 do begin

		inc(i);
		c := tx_2[i];
		tx_row[i] := c;

		if c = N then
		begin
			tx_row[i] := gt1;
			tx_row[i + 1] := gt2;
			inc(i);	 write(f2,'.');  c := '.';
		end;

		write(f2,c);			{////////////////}

		if i mod 50 = 0 then write(f2,N,L);	{ 50 	# # # # # }

	end;



 write(f2,N,L,' ');  write(f2,N,L,' ');



						(*  add & set char  *)
						(*  add & set char  *)



		rem_1 := '       char, frequency   >>>   ';  wrTnl(out, true);


					c := ch253;




							{ set }
			x1 := ord(zero) + frequent;



					{!!!!!  tx_2  !!!!!}

	j := end_txt2 div 2 - 1;
	for i := 0 to j do begin
		c1 := tx_2[2*i + 1];  c2 := tx_2[2*i + 2];

		if not ((c1 = N) and (c2 = L)) then begin

        		c := freq_ch[c1,c2];  k := ord(c);
        		if c > ch253 then k := 253;

						(*  add char  *)

		if choice = 'a' then k := k + 1

		else
						(*  set char  *)

		if choice = 's' then k := x1;
			

        		c := chr(k);  freq_ch[c1,c2] := c;

						(*  used chars  *)

        	c := zero_level[c1,c2];  k := ord(c);
       		if c > ch253 then k := 253 else k := k + 1;
        	c := chr(k);  zero_level[c1,c2] := c;

		end;
		if i mod 15 = 0 then write(f2,N,L);	{ 15 	# # # # # }

				write(f2, c1, c2, c, ' '); {===========}

     end;



 write(f2,N,L); write(f2,N,L);
					{@@@@@@@@@@}

					(*  frequency table  *)

	rem_1 := '          frequency table out            ';
							wrNL(out); {@@@@@}

			freq_tab(out);		{==================}

					{@@@@@@@@@@}




	rem_1 := '\/\/\/\/\/                                        ';
							wrNL(out); {@@@@@}






						(*  new basic table  *)

	if choice  = 'x' then begin

	rem_1 := '          new basic table out                     ';
							wrNL(out); {@@@@@}

			freq_tab2(out);


	rem_1 := '\/\/\/\/\/                                        ';
							wrNL(out); {@@@@@}

	end;


				(*  text out and exclude frequent chars  *)


	rem_1 := '                  exclude frequent chars          ';
							wrNL(out); {@@@@@}


 write(f2,N,L,' ');


		rem_1 := '       limit   >>>   ';  wrTnl(out, true);

			c := info[3];

		rem_1 := '            info[3] = ';  wrTnl(out, false);

		rem_1 := c;  wrTnl(out, false);




 write(f2,N,L,' '); write(f2,N,L,' '); write(f2,N,L,' ');



		rem_1 := '       tx_orgA   >>>   ';  wrTnl(out, true);

							{ tx_org }
	for i := 1 to end_txtA do begin
		c := tx_orgA[i];

		write(f2,c);			{////////////////}

		{ if i mod 50 = 0 then write(f2,N,L); }

	end;


 write(f2,N,L);



		rem_1 := '       tx_2   >>>   ';  wrTnl(out, true);

							{ tx_2 }
	for i := 1 to end_txt2 do begin
		c := tx_2[i];

		write(f2,c);			{////////////////}

		{ if i mod 50 = 0 then write(f2,N,L); }

	end;

 write(f2,N,L);






						(*  ex char  *)
						(*  ex char  *)


					c := ch253;


		rem_1 := '       tx_2, excluded chars   >>>   ';  wrTnl(out, true);


					{!!!!!  tx_2  !!!!!}

	j := end_txt2 div 2 - 1;
	for i := 0 to j do begin

		c1 := tx_2[2*i + 1];  c2 := tx_2[2*i + 2];

		if not ((c1 = N) and (c2 = L)) then begin

			c := freq_ch[c1,c2];
			k := ord(c) - ord(zero);	{ info[4] }
			if k >= frequent then begin
				c1 := per1;  c2 := per2;
			end;
		end;

		write(c1, c2);  write(f2, c1, c2);

	end;









 write(f2,N,L);  write(f2,N,L);  write(f2,N,L);

	rem_1 := '       two times higher frequency   >>>   ';  wrTnl(out, false);

	rem_1 := '       tx_2, excluded chars   >>>   ';  wrTnl(out, true);


					{!!!!!  tx_2     space, NL out  !!!!!}

	j := end_txt2 div 2 - 1;
	for i := 0 to j do begin

		c1 := tx_2[2*i + 1];  c2 := tx_2[2*i + 2];

		if not ((c1 = N) and (c2 = L)) then begin

			c := freq_ch[c1,c2];
			k := ord(c) - ord(zero);	{ info[4] }
			if k >= 2 * frequent then begin
				c1 := per1;  c2 := per2;
			end;
		end;

		write(c1, c2);  write(f2, c1, c2);

	end;


			{///////////////////////////////////////////////}




	rem_1 := '\/\/\/\/\/                                        ';
							wrNL(out); {@@@@@}




		rem_1 := '       used characters      ';
						wrTnl(out, true);




 write(f2,N,L,' ');
							{ space }
	for i := 1 to len_txt do begin
		c := chr(230);				{  230 }
		used[i] := c;
				{write(f2,c); ==============}
	end;

 write(f2,N,L,' ');








		i := 1;

		for  c1 := ch161 to ch254 do 
		for  c2 := ch161 to ch254 do begin

			c := zero_level[c1,c2];

			if c > zero then begin		{ info[4] }

			used[i] := c1;	used[i + 1] := c2;
			end_used := i + 1;  inc(i, 2);

			end;
		end;

write(f2, N, L);


 write(f2,N,L);

	for i := 1 to end_used do begin
		c := used[i];

		write(f2,c);

		if i mod 50 = 0 then write(f2,N,L);	{ 50 	# # # # # }

	end;

 write(f2,N,L,' ');




	rem_1 := '\/\/\/\/\/        ===                             ';
							wrNL(out); {@@@@@}



	{@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  e   }



						{#########}
						{#########}
						{#########}


					{#####          =     #####}



			if (choice = 't') then begin


				{ ------------------ }


			end;	      { choice = 't'  ############ }







	rem_1 := '       E N D   C O D E   P A R T   O N E';  wrTnl(out, true);
	rem_1 := '                  # # # # # ';  wrTnl(out, true);





			{!!!!!!!!!!!!!!!!!!!!}

  {code}

  {exc2}



			{!!!!!!!!!!!!!!!!!!!!}

	{!!!!!!!!!!!!!!!!!!!!  13:39 13.10.2002   -25     }





		rem_1 := '                  # # # # # ';  wrTnl(out, true);
		rem_1 := '       E X C 2     ';  wrTnl(out, true);



	rem_1 := '         fonetics[c1, c2] ';
	wrTnl(out, true);
			choice := 'f';
		{ freq_tab(out); 		\\\\\\     }


	write('   H U O 3  R O N G 2  C A O 3  ');



		rem_1 := '    first   200  GB_list[i]   empty => ":" ';
	wrTnl(out, true);
		rem_1 := '            len_txt = 40000   ';
	wrTnl(out, true);




	for i := 1 to 200 do write(f2, GB_list[i]);  write(f2,N,L);



	i := 0;  new_fon := '';  syllable := '';


	while (i < len_txt - 1) and (c <> '+') do begin
		inc(i);
		c := GB_list[i];
					{ write(f2, c); }
		new_fon := new_fon + c;

		if (GB_list[i] = N) and (GB_list[i + 1] = L) then begin

			inc(i);
			new_fon := new_fon + L;
		(*	write(f2, '@', '-');
			for j := 1 to length(new_fon) do write(f2, new_fon[j]); ////////// *)

		syllable := '';		{ no spaces }

j := 0;
while (new_fon <> '') and (j < length(new_fon))
do begin

		inc(j);  c := new_fon[j];  c1 := c;

		if c1 < ch161 then begin
			if c = TB then c := ' ' else syllable := syllable + c;

		end
		else c2 := new_fon[j + 1];


if not ((GB_list[i] = N) and (GB_list[i + 1] = L)) then begin



	if (c1 >= ch161) and (c2 >= ch161) then begin


		temp := fonetics[c1, c2];  c := temp[1];

		if c = '_' then				{ first }

			fonetics[c1, c2] := syllable
		else					{ all others }

		fonetics[c1, c2] := fonetics[c1, c2] + '+' + syllable;

		inc(j);
	end;

end;	{  ///// not NL }

  end;

		syllable := '';

			{@@@@@@@@@}

		for j := 1 to length(new_fon) - 2 do write(new_fon[j]);

			new_fon := '';
		end;
	end;






		syllable := '  huo3rong2cao3  '; write('  huo3rong2cao3  ');
				rem_1 := syllable;	wrNL(out); {@@@@@}




		rem_1 := '       fonetics, first letter ';  wrTnl(out, true);

		choice := 'f';
		freq_tab(out);





		rem_1 := '                  ========== ';  wrTnl(out, true);
	{ rem_1 := '       text org, tx_2, -128 (&,  166  )   k 3  ';  wrTnl(out, true); }

		{@@@@@}








	write(f2,N,L); write(f2,N,L); write(f2,N,L);



		rem_1 := '                  ========== ';  wrTnl(out, true);
		rem_1 := '        tx_row, fonetics[c1, c2]     ';  wrTnl(out, true);



		{@@@@@}
							{ end_txt2 }


		total := end_txt2 div 20 + 1;
		if total > len_txt - j * 2 then
			total := len_txt - j * 2;


		j := 10;

		{@@@@@}


	for k := 0 to total - 1 do begin

	i := j * k;  while i < j * (k + 1) do begin  write(f2,' ');
	inc(i);  c1 := tx_row[2 * i - 1]; c2 := tx_row[2 * i];
	write(f2,c1,c2,' ');  end;  write(f2,N,L);

	i := j * k;  while i < j * (k + 1) do begin  write(f2,' ');
	inc(i);  c1 := tx_row[2 * i - 1]; c2 := tx_row[2 * i]; 	
	rem_1 := fonetics[c1, c2]; wrTnl(out, false);  	end;   write(f2,N,L);

	end;

	write(f2,N,L); write(f2,N,L); write(f2,N,L);



		{@@@@@}

			{@@@@@}

		{@@@@@}




		rem_1 := '       used characters      ';

							wrTnl(out, true);




 write(f2,N,L);

	for i := 1 to end_used do begin
		c := used[i];

		write(f2,c);

		if i mod 50 = 0 then write(f2,N,L);	{ 50 	# # # # # }

	end;

 write(f2,N,L,' ');





		rem_1 := '       used characters, exclude frequent ones     ';

							wrTnl(out, true);



 write(f2,N,L,' ');
							{ space }
	for i := 1 to len_txt do begin
		c := chr(161);				{  161 }
		used_fr[i] := c;
				{write(f2,c); ==============}
	end;

 write(f2,N,L,' ');




 write(f2,N,L,' ');
							{ space }
	for i := 1 to len_txt do begin
		c := chr(220);				{  220 }
		used_fr2[i] := c;
				{write(f2,c); ==============}
	end;

 write(f2,N,L,' ');






			c := info[3];


		rem_1 := '            info[3]: ';  wrTnl(out, false);

		rem_1 := c;  wrTnl(out, false);

		rem_1 := '   occurs:  >=  ';  wrTnl(out, false);

		rem_1 := c;  wrTnl(out, false);

		rem_1 := '  times ';  wrTnl(out, false);

		rem_1 := '  + 1, + 2, + 3  ';  wrTnl(out, false);


 write(f2,N,L); write(f2,N,L);




		total := end_used div 20 + 1;
		if total > len_txt - j * 2 then
			total := len_txt - j * 2;







			{!!!!!!!!!         !!!!!!!!!}
			{!!!!!!!!!         !!!!!!!!!}


	for x1 := 0 to 3 do begin


 write(f2,N,L); write(f2,N,L);


	i := 1;  i2 := 1;

	while i < end_used do begin

			c1 := used[i];  c2 := used[i + 1];
			c := freq_ch[c1,c2];
			k := ord(c) - ord(zero);	{ info[4] }

					{ + x1 more frequent chars }

			if k >= (frequent + x1) then begin

				c1 := per1;  c2 := per2;
		end

		else begin

			used_fr2[i2] := c1;  used_fr2[i2 + 1] := c2;
			end_uf2 := i2 + 1;  inc(i2, 2);

		end;


		used_fr[i] := c1;  used_fr[i + 1] := c2;

		inc(i, 2);
	end;


 write(f2,N,L); write(f2,N,L);


	for i := 1 to end_used do begin
		c := used_fr[i];

		write(f2,c);

		if i mod 50 = 0 then write(f2,N,L);	{ 50 	# # # # # }

	end;


 write(f2,N,L); write(f2,N,L);



 write(f2,N,L); write(f2,N,L);

	i := 1;

	while i < end_uf2 do begin
		c1 := used_fr2[i];  c2 := used_fr2[i + 1];

		write(f2,c1, c2, ' ', ' ');  inc(i, 2);

		if (i - 1) mod 12 = 0 then write(f2,N,L);	{ 12 	# # # # # }

	end;

 write(f2,N,L); write(f2,N,L);




	i := 1;

	while i < end_uf2 do begin
		c1 := used_fr2[i];  c2 := used_fr2[i + 1];




	rem_1  := ' ' + fonetics[c1, c2] + ' ';

	wrTnlN(out, false, 0);




		inc(i, 2);

		if (i - 1) mod 12 = 0 then write(f2,N,L);	{ 12 	# # # # # }

	end;


 write(f2,N,L); write(f2,N,L);

 write(f2,N,L); write(f2,N,L);




		j := 10;

		{@@@@@}


	for k := 0 to total - 1 do begin

	i := j * k;  while i < j * (k + 1) do begin  write(f2,' ');
	inc(i);  c1 := used_fr[2 * i - 1]; c2 := used_fr[2 * i];
	write(f2,c1,c2,' ');  end;  write(f2,N,L);

	i := j * k;  while i < j * (k + 1) do begin  write(f2,' ');
	inc(i);  c1 := used_fr[2 * i - 1]; c2 := used_fr[2 * i];
	

	rem_1 := fonetics[c1, c2]; wrTnl(out, false);  	end;   write(f2,N,L);

	end;

	write(f2,N,L); write(f2,N,L); write(f2,N,L);





	end;
			{!!!!!!!!!         !!!!!!!!!}
			{!!!!!!!!!         !!!!!!!!!}



		{@@@@@}







		abc:



		rem_1 := '                  ========== ';  wrTnl(out, true);
		rem_1 := '        tx_row, fonetics[c1, c2]     ';  wrTnl(out, true);




			c := info[3];


		rem_1 := '            info[3]: ';  wrTnl(out, false);

		rem_1 := c;  wrTnl(out, false);

		rem_1 := '   occurs:  >=  ';  wrTnl(out, false);

		rem_1 := c;  wrTnl(out, false);

		rem_1 := '  times ';  wrTnl(out, false);

		rem_1 := '  + 1, + 2, + 3  ';  wrTnl(out, false);

		rem_1 := '  *|*|*|*|*|*|*|*|*|*|*  ';  wrTnl(out, true);



 write(f2,N,L); write(f2,N,L);



			{!!!!!!!!!         !!!!!!!!!}
			{!!!!!!!!!         !!!!!!!!!}


	for x1 := 0 to 3 do begin


		{@@@@@}

							{ end_txt2 }

		total := end_txt2 div 20 + 1;
		if total > len_txt - j * 2 then
			total := len_txt - j * 2;


		j := 10;

		{@@@@@}


	for k := 0 to total - 1 do begin

	i := j * k;  while i < j * (k + 1) do begin
	inc(i);  c1 := tx_row[2 * i - 1]; c2 := tx_row[2 * i];
	write(f2,c1,c2);  end;  write(f2,' ',' ',' ');

	i := j * k;  while i < j * (k + 1) do begin
	inc(i);  c1 := tx_row[2 * i - 1]; c2 := tx_row[2 * i];


					{ + x1 more frequent chars }
	c := freq_ch[c1, c2];
	if (ord(c) - ord(zero)) >= (frequent + x1) then

		rem_1 := '-'

	else rem_1  := ' ' + fonetics[c1, c2] + ' ';

	wrTnlN(out, false, 0);  end;   write(f2,N,L);

	end;


	write(f2,N,L); write(f2,N,L); write(f2,N,L);





	end;
			{!!!!!!!!!         !!!!!!!!!}
			{!!!!!!!!!         !!!!!!!!!}


		{@@@@@}

			{@@@@@}

		{@@@@@}















	(*		oooooooooooooooooooooooooooooooooooooooooooooooo




			16:06 13.10.2002   -25


	VOA	www.ocrat.com

  December 12, 1997:   Moon landing anniversary   



             tx_2, fonetics[c1, c2]   k 19  

               һ     
 jin1 tian1 shi4 ren2 lei4 zui4 hou4 yi1 ci4 deng1
                    
 shang4 yue4 qiu2 di4 ji4 nian4 ri4 . . .
         ǰ           
 nian2 . . . qian2 , nei4 ci4 deng1 yue4
                 Ա   
 ren4 wu4 zhong4 di4 liang3 ming2 yu3 hang2 yun4 zai4
       һ            ʱ 
 ji4 nian4 zhei4 yi1 . . . tian1 di4 shi2
     ǿ               
 hou4 , qiang3 tiao2 liao4 yue4 qiu2 dui4 di4 qiu2
   δ        ô         
 di4 wei4 lai2 shi4 duo1 me5 di4 . . .
   Ҫ            ǰ     
 zhong4 yao4 liao4 . zhei4 liang3 ming2 qian2 yu3 hang2
 Ա  ˵        Ӧ         
 yun4 yue4 , mei3 guo2 ying4 gai1 zhi4 ding4 zhong4
                    
 . . . fan3 yue4 qiu2 di4 ji4 huai5 .
             ֮       
 xia4 mian4 shi4 < mei3 guo2 zhi1 yin1 > ke1
 ѧ                   
 xue2 bian1 ji2 . . . mai4 qia3 la4 rui4
         ϸ           
 bao4 dao4 di4 xiang2 xi4 nei4 rong2 . . .



 append

O	
=	
.	
,	
:	
?	
"	
"	
'	
'	
<	
>	



		rem_1 := '                  # # # # # ';  wrTnl(out, true);
		rem_1 := '       E X C 2     ';  wrTnl(out, true);

		rem_1 := '       E N D   E X C 2     ';  wrTnl(out, true);
		rem_1 := '                  # # # # # ';  wrTnl(out, true);


	oooooooooooooooooooooooo    e 4g2   f8  8    *)


			{!!!!!!!!!!!!!!!!!!!!}
			{!!!!!!!!!!!!!!!!!!!!}





		rem_1 := '       E N D   E X C 2     ';  wrTnl(out, true);
		rem_1 := '                  # # # # # ';  wrTnl(out, true);

   end;



				(*     f     3.10.2002     *)
 (*  main  *)
 (*   *)

  {exc2}


  {tab_end}

 (*   *)
 (*  end  *)
				(*     g    12:58 13.10.2002    *)

{WWWWWWWWWW}

                               (* extern table in *)



   procedure TabInit(var f1, f2 : ch_file);
   var  i : integer;  c, ci, cj, N, L : char;

   begin  

      N := chr(13);  L := chr(10);

		GB := true; Big5 := false; GB_Big5 := true;

      for i := 1 to 255 do info[i] := ' ';

      i := 0;

      while not (eof(f1) or (c = '*')) do begin
         inc(i);  read(f1, c);  info[i] := c;
      end;

(* --- *)


	choice := info[1];

	base := info[2];		{ new table }

	c := info[3];

	i := ord(c);  if (i >= 48) and (i <= 57) then i := i - 48 else i := 2;
	frequent := i;			{ exclude chars, used chars }

	zero := info[4];		{ exclude chars, used chars }





	{ c := info[6]; }

	i := ord(c);  if (i >= 48) and (i <= 57) then i := i - 48 else i := 2;
	total := i * 20;			{ exclude chars, used chars }


	if info[10] = 'G' then begin

	   	GB := true; Big5 := false; GB_Big5 := true;
	end;

	if info[10] = 'B' then begin

	   	GB := false; Big5 := true; GB_Big5 := false;
	end;



			   	GB := true;		{ GB pre-set ##### }





					{ $ "zero" }

 write(' ', '$');write(f2, ' ', '$', ' ', zero);

      for  ci := ch161 to ch254 do
      for  cj := ch161 to ch254 do begin
         freq_ch[ci,cj] := '$';  zero_level[ci,cj] := zero;
      end;

						{ char c }
      for  ci := ch161 to ch254 do
      for  cj := ch161 to ch254 do begin
         if eof(f1) then exit;
         repeat begin
            read(f1, c);  if eof(f1) then exit;
         end;
         until c >= ' ';			{  skip tab, NL  }
         freq_ch[ci,cj] := c;
      end;




					{#####          =     #####}


						{#########}
						{#########}
						{#########}


	rem_1 := '                  ========== ';  wrTnl(out, true);

	rem_1 := '       = = = = =          26.10.2002    ';  wrTnl(out, true);






					{ _@ + space "zero" }

					{ '_@ ' "zero" }

	write(' ', '!', '!', '!');write(f2, ' ', '!', '!', '!');

	for  ci := ch161 to ch254 do
	for  cj := ch161 to ch254 do
	fonetics[ci,cj] := '_@ '; 




				{ test fonetics ///////////// }





	rem_1 := '                  ========== ';  wrTnl(out, true);
	rem_1 := '         read   info2[i]   GB table in  ';  wrTnl(out, true);



	i := 0;
	
	while not (eof(f1) or (c = '*')) do begin
		inc(i);  read(f1, c);  info2[i] := c;

		if choice = 'x' then			write(f2, c);
		if choice = 'f' then			write(f2, c);
	end;



	rem_1 := '                  ========== ';  wrTnl(out, true);
	rem_1 := '         read   GB_list[i]   GB table in  ';  wrTnl(out, true);




	temp := '((((((((((';


	rem_1 := '                  ========== ';  wrTnl(out, true);
	rem_1 := '        GB_list[i]   - x -     ';  wrTnl(out, true);



							{ ':' "zero" }
	for  i := 1 to len_txt do GB_list[i] := ':';


	i := 0;

	while not (eof(f1) or (c = '+')) do begin
		inc(i);  read(f1, c);
		GB_list[i] := c;
							{ GB_list[i] }

		if choice = 'x' then			write(f2, c);

	end;






	rem_1 := '                  ========== ';  wrTnl(out, true);
	rem_1 := '        TabInit end     ';  wrTnl(out, true);


	(* rem_1 := 'xyz xyz xyz xyz xyz        x x x x   ';
					wrTnlN(out, true, 3); *)



   end;








{WWWWWWWWWW}

                            (* suggestion for use *)
   procedure syntax;
   begin
      writeln('Syntax,  suggestion for use ');
      writeln('   ivm pasprog xx.txt tabchinc.txt xxxxx.txt');
      writeln(' "xx.txt"     input file');
      writeln(' "tabchinc.txy"  coding table file');
      writeln(' "xxxxx.txt"     output file');
      halt
   end;

 begin
   if paramcount <> 3 then
      syntax;

		{    assign(f, paramstr(1)); type2 }

   assign(in1, paramstr(1));
   assign(tabchinc, paramstr(2));
   assign(out, paramstr(3));

   rewrite(out);
   reset(in1);
   reset(tabchinc); 
   TabInit(tabchinc, out);
   Code(in1, out);
   close(in1);
   close(tabchinc);
   close(out)
 end.

 (* *)
 (* *)
 (* *)
 (* *)



	(*

	rem_1 := '                  ========== ';  wrTnl(out, true);
	rem_1 := '        x     ';  wrTnl(out, true);

	*)


 (*     cn2.p        *)
 (*     13.10.1999     *)


				{     g    14:12 26.10.2002     }
 (*  end  *)
 (* *)

  {tab_end}

