home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 December / Chip_2002-12_cd1.bin / tema / clin / CLIN.EXE / SRC / SRC.RAR / KODA.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-09-27  |  11.3 KB  |  224 lines

  1. // Code 128
  2. Unit KodA;
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  8.   Dialogs, StdCtrls, ExtCtrls,
  9.   U;
  10.  
  11.  procedure HCA(var Co:TMemo);
  12.  procedure S2LA(Co:String; StartStop:Boolean; Crc:Boolean    ; var Raw:String; var RawS:String; var Bits:String);
  13.  
  14.  
  15. implementation
  16.  
  17.  const MaxKod=106;
  18.  var Kody:Array[0..106]of record
  19.        Asc,Asc2,Asc3:String;
  20.        Kod:Byte;
  21.        Line:String;
  22.      end;
  23.  
  24.  procedure HCA(var Co:TMemo);
  25.  var I:Word;
  26.  begin
  27.   Co.Clear;
  28.   for I:=0 to MaxKod do
  29.    with Kody[I] do
  30.      begin
  31.        Co.Lines.Add(Hex(Kod)+'  '+Asc+' / '+Asc2+' / '+Asc3+' ('+Line+')');
  32.      end;
  33.  end;
  34.  
  35.  procedure S2LA(Co:String; StartStop:Boolean; Crc:Boolean    ; var Raw:String; var RawS:String; var Bits:String);
  36.  var I,J,K:Integer;
  37.      Pom,Pom2:String;
  38.      PomC:Byte;
  39.      E:Integer;
  40.      Ch:Byte;
  41.  begin
  42.    Raw:='';
  43.    RawS:='';
  44.    Bits:='';
  45.    if Length(Co)=0 then Exit;
  46.  //// Vy°a∩ neplatnΘ a zkonvertuj HEX verze
  47.    I:=1;
  48.    while I<=Length(Co) do
  49.    begin
  50.      //// Je to $ ?
  51.      if Co[I]='$' then // Je to HEX
  52.         begin
  53.           Pom:='';
  54.           repeat
  55.             Pom:=Pom+Co[I];
  56.             I:=I+1; // Posu≥ o dalÜφ znak
  57.           until (length(Pom)=3) or (I>Length(Co));
  58.           if I<=Length(Co) then I:=I-1;
  59.           Val(Pom,PomC,E);
  60.           if (E=0)and(PomC<=MaxKod) then
  61.           begin
  62.             Raw:=Raw+Chr(PomC);
  63.           end;
  64.         end else
  65.         begin   // Nenφ to HEX
  66.           for J:=0 to MaxKod do
  67.             if Co[I]=Kody[J].Asc2 then Raw:=Raw+Chr(Kody[J].Kod);
  68.         end;
  69.      I:=I+1;
  70.    end;
  71.  //// Crc a Start/Stop
  72.    if Crc then
  73.    begin
  74.      J:=0;
  75.      for I:=1 to Length(Raw) do
  76.      begin
  77.        J:=J+Ord(Raw[I]);
  78.      end;
  79.      Raw:=Raw+Chr(J mod 103);
  80.    end;
  81.  
  82.    if StartStop then Raw:=#104+Raw+#106;
  83.  //// Na zobrazitelne
  84.       //// +Na bity
  85.  for I:=1 to Length(Raw) do
  86.   begin
  87.     RawS:=RawS+Kody[Ord(Raw[I])].Asc2;
  88.     Pom2:=Kody[Ord(Raw[I])].Line;
  89.       Pom:='';
  90.       Ch:=$31; // ZaΦφnßme jedniΦkou
  91.       for J:=1 to Length(Pom2) do
  92.       begin
  93.         for K:=1 to (Ord(Pom2[J])-$30) do // Pozor na 0-x a 1-x v tabulce bit∙ !!!
  94.           begin
  95.             Pom:=Pom+Chr(Ch);
  96.           end;
  97.         Ch:=Ch xor 1;
  98.       end;
  99.      Bits:=Bits+Pom;
  100.   end;
  101.  end;
  102.  
  103. begin
  104.  with Kody[000]do begin Asc:=' ';Asc2:=' ';Asc3:='00';Kod:=0;Line:='212222';end;
  105.  with Kody[001]do begin Asc:='!';Asc2:='!';Asc3:='01';Kod:=1;Line:='222122';end;
  106.  with Kody[002]do begin Asc:='"';Asc2:='"';Asc3:='02';Kod:=2;Line:='222221';end;
  107.  with Kody[003]do begin Asc:='#';Asc2:='#';Asc3:='03';Kod:=3;Line:='121223';end;
  108.  with Kody[004]do begin Asc:='$';Asc2:='$';Asc3:='04';Kod:=4;Line:='121322';end;
  109.  with Kody[005]do begin Asc:='%';Asc2:='%';Asc3:='05';Kod:=5;Line:='131222';end;
  110.  with Kody[006]do begin Asc:='&';Asc2:='&';Asc3:='06';Kod:=6;Line:='122213';end;
  111.  with Kody[007]do begin Asc:=''';Asc2:=''';Asc3:='07';Kod:=7;Line:='122312';end;
  112.  with Kody[008]do begin Asc:='(';Asc2:='(';Asc3:='08';Kod:=8;Line:='132212';end;
  113.  with Kody[009]do begin Asc:=')';Asc2:=')';Asc3:='09';Kod:=9;Line:='221213';end;
  114.  
  115.  with Kody[010]do begin Asc:='*';Asc2:='*';Asc3:='10';Kod:=10;Line:='221312';end;
  116.  with Kody[011]do begin Asc:='+';Asc2:='+';Asc3:='11';Kod:=11;Line:='231212';end;
  117.  with Kody[012]do begin Asc:=',';Asc2:=',';Asc3:='12';Kod:=12;Line:='112232';end;
  118.  with Kody[013]do begin Asc:='-';Asc2:='-';Asc3:='13';Kod:=13;Line:='122132';end;
  119.  with Kody[014]do begin Asc:='.';Asc2:='.';Asc3:='14';Kod:=14;Line:='122231';end;
  120.  with Kody[015]do begin Asc:='/';Asc2:='/';Asc3:='15';Kod:=15;Line:='113222';end;
  121.  with Kody[016]do begin Asc:='0';Asc2:='0';Asc3:='16';Kod:=16;Line:='123122';end;
  122.  with Kody[017]do begin Asc:='1';Asc2:='1';Asc3:='17';Kod:=17;Line:='123221';end;
  123.  with Kody[018]do begin Asc:='2';Asc2:='2';Asc3:='18';Kod:=18;Line:='223211';end;
  124.  with Kody[019]do begin Asc:='3';Asc2:='3';Asc3:='19';Kod:=19;Line:='221132';end;
  125.  
  126.  with Kody[020]do begin Asc:='4';Asc2:='4';Asc3:='20';Kod:=20;Line:='221231';end;
  127.  with Kody[021]do begin Asc:='5';Asc2:='5';Asc3:='21';Kod:=21;Line:='213212';end;
  128.  with Kody[022]do begin Asc:='6';Asc2:='6';Asc3:='22';Kod:=22;Line:='223112';end;
  129.  with Kody[023]do begin Asc:='7';Asc2:='7';Asc3:='23';Kod:=23;Line:='312131';end;
  130.  with Kody[024]do begin Asc:='8';Asc2:='8';Asc3:='24';Kod:=24;Line:='311222';end;
  131.  with Kody[025]do begin Asc:='9';Asc2:='9';Asc3:='25';Kod:=25;Line:='321122';end;
  132.  with Kody[026]do begin Asc:=':';Asc2:=':';Asc3:='26';Kod:=26;Line:='321221';end;
  133.  with Kody[027]do begin Asc:=';';Asc2:=';';Asc3:='27';Kod:=27;Line:='312212';end;
  134.  with Kody[028]do begin Asc:='<';Asc2:='<';Asc3:='28';Kod:=28;Line:='322112';end;
  135.  with Kody[029]do begin Asc:='=';Asc2:='=';Asc3:='29';Kod:=29;Line:='322211';end;
  136.  
  137.  with Kody[030]do begin Asc:='>';Asc2:='>';Asc3:='30';Kod:=30;Line:='212123';end;
  138.  with Kody[031]do begin Asc:='?';Asc2:='?';Asc3:='31';Kod:=31;Line:='212321';end;
  139.  with Kody[032]do begin Asc:='@';Asc2:='@';Asc3:='32';Kod:=32;Line:='232121';end;
  140.  with Kody[033]do begin Asc:='A';Asc2:='A';Asc3:='33';Kod:=33;Line:='111323';end;
  141.  with Kody[034]do begin Asc:='B';Asc2:='B';Asc3:='34';Kod:=34;Line:='131123';end;
  142.  with Kody[035]do begin Asc:='C';Asc2:='C';Asc3:='35';Kod:=35;Line:='131321';end;
  143.  with Kody[036]do begin Asc:='D';Asc2:='D';Asc3:='36';Kod:=36;Line:='112313';end;
  144.  with Kody[037]do begin Asc:='E';Asc2:='E';Asc3:='37';Kod:=37;Line:='132113';end;
  145.  with Kody[038]do begin Asc:='F';Asc2:='F';Asc3:='38';Kod:=38;Line:='132311';end;
  146.  with Kody[039]do begin Asc:='G';Asc2:='G';Asc3:='39';Kod:=39;Line:='211313';end;
  147.  
  148.  with Kody[040]do begin Asc:='H';Asc2:='H';Asc3:='40';Kod:=40;Line:='231113';end;
  149.  with Kody[041]do begin Asc:='I';Asc2:='I';Asc3:='41';Kod:=41;Line:='231311';end;
  150.  with Kody[042]do begin Asc:='J';Asc2:='J';Asc3:='42';Kod:=42;Line:='112133';end;
  151.  with Kody[043]do begin Asc:='K';Asc2:='K';Asc3:='43';Kod:=43;Line:='112331';end;
  152.  with Kody[044]do begin Asc:='L';Asc2:='L';Asc3:='44';Kod:=44;Line:='132131';end;
  153.  with Kody[045]do begin Asc:='M';Asc2:='M';Asc3:='45';Kod:=45;Line:='113123';end;
  154.  with Kody[046]do begin Asc:='N';Asc2:='N';Asc3:='46';Kod:=46;Line:='113321';end;
  155.  with Kody[047]do begin Asc:='O';Asc2:='O';Asc3:='47';Kod:=47;Line:='133121';end;
  156.  with Kody[048]do begin Asc:='P';Asc2:='P';Asc3:='48';Kod:=48;Line:='313121';end;
  157.  with Kody[049]do begin Asc:='Q';Asc2:='Q';Asc3:='49';Kod:=49;Line:='211331';end;
  158.  
  159.  with Kody[050]do begin Asc:='R';Asc2:='R';Asc3:='50';Kod:=50;Line:='231131';end;
  160.  with Kody[051]do begin Asc:='S';Asc2:='S';Asc3:='51';Kod:=51;Line:='213113';end;
  161.  with Kody[052]do begin Asc:='T';Asc2:='T';Asc3:='52';Kod:=52;Line:='213311';end;
  162.  with Kody[053]do begin Asc:='U';Asc2:='U';Asc3:='53';Kod:=53;Line:='213131';end;
  163.  with Kody[054]do begin Asc:='V';Asc2:='V';Asc3:='54';Kod:=54;Line:='311123';end;
  164.  with Kody[055]do begin Asc:='W';Asc2:='W';Asc3:='55';Kod:=55;Line:='311321';end;
  165.  with Kody[056]do begin Asc:='X';Asc2:='X';Asc3:='56';Kod:=56;Line:='331121';end;
  166.  with Kody[057]do begin Asc:='Y';Asc2:='Y';Asc3:='57';Kod:=57;Line:='312113';end;
  167.  with Kody[058]do begin Asc:='Z';Asc2:='Z';Asc3:='58';Kod:=58;Line:='312311';end;
  168.  with Kody[059]do begin Asc:='[';Asc2:='[';Asc3:='59';Kod:=59;Line:='332111';end;
  169.  
  170.  with Kody[060]do begin Asc:='\';Asc2:='\';Asc3:='60';Kod:=60;Line:='314111';end;
  171.  with Kody[061]do begin Asc:=']';Asc2:=']';Asc3:='61';Kod:=61;Line:='221411';end;
  172.  with Kody[062]do begin Asc:='^';Asc2:='^';Asc3:='62';Kod:=62;Line:='431111';end;
  173.  with Kody[063]do begin Asc:='_';Asc2:='_';Asc3:='63';Kod:=63;Line:='111224';end;
  174.  with Kody[064]do begin Asc:='{NUL}';Asc2:='`';Asc3:='64';Kod:=64;Line:='111422';end;
  175.  with Kody[065]do begin Asc:='{SOH}';Asc2:='a';Asc3:='65';Kod:=65;Line:='121124';end;
  176.  with Kody[066]do begin Asc:='{STX}';Asc2:='b';Asc3:='66';Kod:=66;Line:='121421';end;
  177.  with Kody[067]do begin Asc:='{ETX}';Asc2:='c';Asc3:='67';Kod:=67;Line:='141122';end;
  178.  with Kody[068]do begin Asc:='{EOT}';Asc2:='d';Asc3:='68';Kod:=68;Line:='141221';end;
  179.  with Kody[069]do begin Asc:='{ENQ}';Asc2:='e';Asc3:='69';Kod:=69;Line:='112214';end;
  180.  
  181.  with Kody[070]do begin Asc:='{ACK}';Asc2:='f';Asc3:='70';Kod:=70;Line:='112412';end;
  182.  with Kody[071]do begin Asc:='{BEL}';Asc2:='g';Asc3:='71';Kod:=71;Line:='122114';end;
  183.  with Kody[072]do begin Asc:='{BS}';Asc2:='h';Asc3:='72';Kod:=72;Line:='122411';end;
  184.  with Kody[073]do begin Asc:='{HT}';Asc2:='i';Asc3:='73';Kod:=73;Line:='142112';end;
  185.  with Kody[074]do begin Asc:='{LF}';Asc2:='j';Asc3:='74';Kod:=74;Line:='142211';end;
  186.  with Kody[075]do begin Asc:='{VT}';Asc2:='k';Asc3:='75';Kod:=75;Line:='241211';end;
  187.  with Kody[076]do begin Asc:='{FF}';Asc2:='l';Asc3:='76';Kod:=76;Line:='221114';end;
  188.  with Kody[077]do begin Asc:='{CR}';Asc2:='m';Asc3:='77';Kod:=77;Line:='413111';end;
  189.  with Kody[078]do begin Asc:='{SO}';Asc2:='n';Asc3:='78';Kod:=78;Line:='241112';end;
  190.  with Kody[079]do begin Asc:='{SI}';Asc2:='o';Asc3:='79';Kod:=79;Line:='134111';end;
  191.  
  192.  with Kody[080]do begin Asc:='{DLE}';Asc2:='p';Asc3:='80';Kod:=80;Line:='111242';end;
  193.  with Kody[081]do begin Asc:='{DC1}';Asc2:='q';Asc3:='81';Kod:=81;Line:='121142';end;
  194.  with Kody[082]do begin Asc:='{DC2}';Asc2:='r';Asc3:='82';Kod:=82;Line:='121241';end;
  195.  with Kody[083]do begin Asc:='{DC3}';Asc2:='s';Asc3:='83';Kod:=83;Line:='114212';end;
  196.  with Kody[084]do begin Asc:='{DC4}';Asc2:='t';Asc3:='84';Kod:=84;Line:='124112';end;
  197.  with Kody[085]do begin Asc:='{NAK}';Asc2:='u';Asc3:='85';Kod:=85;Line:='124211';end;
  198.  with Kody[086]do begin Asc:='{SYN}';Asc2:='v';Asc3:='86';Kod:=86;Line:='411212';end;
  199.  with Kody[087]do begin Asc:='{ETB}';Asc2:='w';Asc3:='87';Kod:=87;Line:='421112';end;
  200.  with Kody[088]do begin Asc:='{CAN}';Asc2:='x';Asc3:='88';Kod:=88;Line:='421211';end;
  201.  with Kody[089]do begin Asc:='{EM}';Asc2:='y';Asc3:='89';Kod:=89;Line:='212141';end;
  202.  
  203.  with Kody[090]do begin Asc:='{SUB}';Asc2:='z';Asc3:='90';Kod:=90;Line:='214121';end;
  204.  with Kody[091]do begin Asc:='{ESC}';Asc2:='{';Asc3:='91';Kod:=91;Line:='412121';end;
  205.  with Kody[092]do begin Asc:='{FS}';Asc2:='|';Asc3:='92';Kod:=92;Line:='111143';end;
  206.  with Kody[093]do begin Asc:='{GS}';Asc2:='}';Asc3:='93';Kod:=93;Line:='111341';end;
  207.  with Kody[094]do begin Asc:='{RS}';Asc2:='~';Asc3:='94';Kod:=94;Line:='131141';end;
  208.  with Kody[095]do begin Asc:='{US}';Asc2:='{DEL}';Asc3:='95';Kod:=95;Line:='114113';end;
  209.  with Kody[096]do begin Asc:='{FNC3}';Asc2:='{FNC3}';Asc3:='96';Kod:=96;Line:='113311';end;
  210.  with Kody[097]do begin Asc:='{FNC2}';Asc2:='{FNC2}';Asc3:='97';Kod:=97;Line:='411113';end;
  211.  with Kody[098]do begin Asc:='{ SHIFT }';Asc2:='{ SHIFT }';Asc3:='98';Kod:=98;Line:='411311';end;
  212.  with Kody[099]do begin Asc:='{ CODE C }';Asc2:='{ CODE C }';Asc3:='99';Kod:=99;Line:='113141';end;
  213.  
  214.  with Kody[100]do begin Asc:='{ CODE B }';Asc2:='{FNC4}';Asc3:='{ CODE B }';Kod:=100;Line:='114131';end;
  215.  with Kody[101]do begin Asc:='{FNC4}';Asc2:='{ CODE A }';Asc3:='{ CODE A }';Kod:=101;Line:='311141';end;
  216.  with Kody[102]do begin Asc:='{FNC1}';Asc2:='{FNC1}';Asc3:='{FNC1}';Kod:=102;Line:='411131';end;
  217.  
  218.  with Kody[103]do begin Asc:='{ START A }';Asc2:=Asc;Asc3:=Asc;Kod:=103;Line:='211412';end;
  219.  with Kody[104]do begin Asc:='{ START B }';Asc2:=Asc;Asc3:=Asc;Kod:=104;Line:='211214';end;
  220.  with Kody[105]do begin Asc:='{ START C }';Asc2:=Asc;Asc3:=Asc;Kod:=105;Line:='211232';end;
  221.  
  222.  with Kody[106]do begin Asc:='{ STOP }';Asc2:=Asc;Asc3:=Asc;Kod:=106;Line:='2331112';end;
  223. end.
  224.