home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 March / PCWorld_2002-03_cd.bin / Software / Komercni / far / Far1703.exe / Addons / Tables / README.TXT < prev   
Encoding:
Text File  |  2001-04-16  |  2.8 KB  |  116 lines

  1. This folder contains character tables for viewer, editor and "Find file"
  2. command and character frequency distribution tables.
  3.  
  4. Read file descriptions for contents of the tables.
  5.  
  6. 1. Dist
  7. ~~~~~~~
  8.  
  9. Character frequency distribution information is required in order to
  10. autodetect the table in viewer and editor (you do not need it if you use
  11. only one character table). It describes characters frequency for OEM codepage
  12. of concrete language. 0 corresponds to lowest frequency, 254 to highest,
  13. value 255 means that this character should be ignored when analysing file.
  14.  
  15. The simple C++ program below can be used to generate frequency distribution
  16. information for your language. It has only one parameter - the name of a
  17. large enough text file in OEM codepage which is typical of the language used.
  18.  
  19.  
  20. #include <stdio.h>
  21.  
  22. void main(int Argc, char *Argv[])
  23. {
  24.   if (Argc!=2)
  25.   {
  26.     printf("\nSyntax: DISTR <file>");
  27.     return;
  28.   }
  29.   FILE *SrcFile=fopen(Argv[1],"rb");
  30.   if (SrcFile==NULL)
  31.   {
  32.     printf("\nCannot open %s",Argv[1]);
  33.     return;
  34.   }
  35.   unsigned long Count[256],MaxCount=0;
  36.  
  37.   for (int I=0;I<sizeof(Count)/sizeof(Count[0]);I++)
  38.     Count[I]=0;
  39.  
  40.   int Ch,PrevCh=0;
  41.   while ((Ch=fgetc(SrcFile))!=EOF)
  42.     if (Ch!=PrevCh)
  43.       Count[Ch]++;
  44.   fclose(SrcFile);
  45.  
  46.   for (int I=128;I<sizeof(Count)/sizeof(Count[0]);I++)
  47.     if (MaxCount<Count[I])
  48.       MaxCount=Count[I];
  49.   int Divider=MaxCount/254;
  50.   if (Divider<10)
  51.   {
  52.     printf("\nSource file too small");
  53.     return;
  54.   }
  55.   printf("REGEDIT4\n\n[HKEY_CURRENT_USER\\Software\\Far\\CodeTables]\n\"Distribution\"=hex:\\\n    ");
  56.   for (int I=0;I<256;I++)
  57.   {
  58.     int Value;
  59.     if (I<128 && (I>=32 || Count[I]!=0))
  60.       Value=0xff;
  61.     else
  62.       if ((Value=Count[I]/Divider)>254)
  63.         Value=254;
  64.     printf("%02x%s",Value,I!=255 ? ",":"");
  65.     if (I%16==15 && I!=255)
  66.       printf("\\\n    ");
  67.   }
  68.   printf("\n");
  69. }
  70.  
  71.  
  72. 2. Win
  73. ~~~~~~
  74.  
  75. If you want to generate a WINDOWS character table, to use it in the
  76. FAR (it is displayed as "Win" in the translation table list), you can use
  77. the following C/C++ program. It will display the current table on the
  78. stdout. In order to write a generated table in the file win.reg, type
  79. in the command line prompt: WinCTGen.exe>win.reg.
  80.  
  81. #include <windows.h>
  82. #include <stdio.h>
  83.  
  84. int main()
  85. {
  86.   int Chr[256], I, J, P;
  87.   char b[2];
  88.   b[1]=0;
  89.  
  90.   for(I=0;I<256;I++)
  91.   {
  92.     b[0]=I;
  93.     CharToOem(b,b);
  94.     Chr[I]=(unsigned char)b[0];
  95.   }
  96.  
  97.   printf("REGEDIT4\n\n[HKEY_CURRENT_USER\\Software\\Far\\CodeTables\\Win]\n\"Mapping\"=hex:");
  98.  
  99.   for(I=0;I<21;I++)
  100.     printf("%02x,",Chr[I]);
  101.   printf("\\\n  ");
  102.  
  103.   for(J=0;J<9;J++)
  104.   {
  105.     for(P=0;P<25;P++, I++)
  106.       printf("%02x,",Chr[I]);
  107.     printf("\\\n  ");
  108.   }
  109.  
  110.   for(;I<255;I++)
  111.     printf("%02x,",Chr[I]);
  112.   printf("%02x\n",Chr[I]);
  113.  
  114.   return 0;
  115. }
  116.