Trsek Commander - Substitute of Norton Commander, pascal

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Category: Source in Pascal
tc.pngProgram: Tc.pas
File exe: Tc.exe
need: Main.pasMouse.pasT_wind.pas

The purpose of this program is to substitute Norton Commander. It has had a great beginning and this program is a result. However, as it is with other similar projects, this one couldn't move at one point. At present it is possible to view the files in the window which can be enlarged or moved voluntarily by a mouse.
{ TC.PAS                    Copyright (c) TrSek alias Zdeno Sekerak }
{ TrSek Commander                                                   }
{ Program si kladie za ciel napodobnit Norton Commander.            }
{ V tejto verzii obsahuje vypis adresara s moznostou menit velkost  }
{ a poziciu okna.                                                   }
{                                                                   }
{ Datum:28.07.1996                             http://www.trsek.com }
 
{$M 21192,0,65360}
program trsek_commander;
uses t_wind,crt,dos;
const mapa_kl:array[1..50] of char=             { mapa ALT klavesnice }
      ('1','2','3','4','5','6','7','8','9','0','_','+',' ',' ',' ',
       'Q','W','E','R','T','Y','U','I','O','P',' ',' ',' ',' ','A',
       'S','D','F','G','H','J','K','L',' ',' ',' ',' ',' ','Z','X',
       'C','V','B','N','M');
      po_full=4;            { pocet stlpcov pri full zobrazovani }
                            { a tu su napisane }
      ro_full:array[1..po_full] of byte=(12,23,32,38);
                            { pre texty nad full }
      mo_full:array[1..po_full] of byte=(0,13,24,33);
 
      okno_bm='    Name    ';                 { nazov suborov pre brief vypis }
      okno_fm:array[1..po_full] of string=    { nazov suborov pre full vypis }
      ('    Name    ','   Size   ','  Date  ','Time ');
 
type t_DTA=record
      disk:Byte;
      meno:Array[1..8] of char;
      prip:Array[1..3] of char;
      Attr:Byte;
      cpoladr:Word;
      clusadr:Word;
      bla:Array[1..4] of char;
      atr:byte;
      cas:word;
      datum:word;
      size:LongInt;
      meno_kon:Array[1..13] of char;
      buffer:word;                      { co s tym, naco to asi sluzi ??? }
     end;
 
 t_subor=record
       pred:pointer;
       atr:byte;
       cas:word;
       datum:word;
       size:LongInt;
       meno_kon:string[12];
       oznac:boolean;           { je oznaceny subor ? }
       zani:pointer;
      end;
 
 t_full=(full,brief,norm);
 
 t_okno=record
       xh,yh,xd,yd:byte;
       c_okna:byte;
       aktu:byte;
       p_subor,k_subor,l_subor:^t_subor;
       pocx,pocy:byte;
       poccel:integer;              { kolko sa vojde do okna }
       pocet:integer;               { kolko je suborov v adresari }
       sort:byte;                   { sposob sortovania }
       o_full:t_full;               { vypisovat full/brief/ramcek }
       attr:word;
       pole_okna:pointer;           { smernik na podklad }
       subor:pointer;               { pointer pre subory (na prvy) }
       cesta:string;                { okno ma cestu (dir) }
      end;
 
var d_attr:word;                { nastavuje default hodnoty }
    okno:t_okno;
    i:integer;            { bez komentara }
    mouse:boolean;
    x,y:byte;
    uziv_obr:array[1..80,1..25] of byte;  { kde ake okno atd ... }
 
{$I mouse.pas }
{$I main.pas }
 
procedure rezidenty;                    { stara sa o programy, ktore maju }
begin                                   { bezat akoze rezidentne }
 timexy(72,0);
end;
 
{ proste caka pokial nepusti tlacitko na mysi }
procedure no_mouse;
var x,y,but:byte;
begin
 repeat
  get_mouse(x,y,but);
 until (but=0);
end;
 
{ odpalil som enterom exe, com, bat zatial nefunguje tak neviem co dalej }
procedure run_exe(run:string);
begin
  SwapVectors;
  Exec(GetEnv('COMSPEC'), '/C '+run);
  SwapVectors;
end;
 
{ stlacil enter(double-klick mouse) na subor alebo adresar }
procedure press_enter(var kurx,kury:byte;p_okno:pointer);
var okno:^t_okno;
    old_ces:string;
    exten:string[3];
begin
 okno:=p_okno;
 if (okno^.k_subor^.atr and $10)=$10 then begin
     uvolni_f(okno^.subor);
     old_ces:=okno^.cesta;
     if (okno^.k_subor^.meno_kon[10]<>' ') then okno^.k_subor^.meno_kon[9]:='.';
     okno^.cesta:=no_space(okno^.cesta+'\'+okno^.k_subor^.meno_kon);
     okno^.subor:=napln_f('*.*',AnyFile-VolumeID,okno^.pocet);
     sortuj(okno^.sort);
     okno^.p_subor:=okno^.subor;
     kury:=1;kurx:=0;
     text_okno(okno^.o_full);
     vypis_o(okno^.p_subor,zarovnaj(copy(old_ces,ord(okno^.cesta[0])+2,80),12),kurx,kury);
    end
   else begin
    exten:=copy(okno^.k_subor^.meno_kon,10,3);
    if (exten='exe') or (exten='com') or (exten='bat') then begin
        vepo_podkl(okno^.xh,okno^.xd,okno^.yh,okno^.yd,okno^.pole_okna,false);
        uvolni_mpole(okno^.pole_okna);
        uvolni_f(okno^.subor);
        old_ces:=okno^.k_subor^.meno_kon;
        okno^.k_subor^.meno_kon[9]:='.';
        run_exe(no_space(okno^.k_subor^.meno_kon));
 
        urobpole(okno^.xh,okno^.xd,okno^.yh,okno^.yd,okno^.pole_okna);
        okno^.subor:=napln_f('*.*',AnyFile-VolumeID,okno^.pocet);
        sortuj(okno^.sort);
        vepo_podkl(okno^.xh,okno^.xd,okno^.yh,okno^.yd,okno^.pole_okna,true);
        text_okno(okno^.o_full);
        vypis_o(okno^.p_subor,old_ces,kurx,kury);
       end;
   end;
end;
 
procedure v_okno(subor:pointer);
var kury,kurx:byte;                          { kurzor }
    p_vypis,k_vypis:pointer;
    po_subor:^t_subor;
    pom:pointer;
    ch:char;
    old_file:string;
    x,y,i,but,alti:byte;
begin
 p_vypis:=okno.p_subor;                      { aktualna pozicia vypisovania }
 k_vypis:=NIL;
 
 kury:=1;kurx:=0;but:=0;ch:=#0;alti:=0;
 old_file:=nothing(13);
 show_mouse(true);
 repeat
  if (k_vypis<>okno.k_subor) then begin
     writexy_s(okno.xh,kurx,okno.yh+kury,14,okno.o_full,okno.k_subor);
     twritexy(okno.xh,okno.yd-2,14,zarovnaj(disp(okno.k_subor,' '),okno.xd-okno.xh-1)+nothing(78));
     k_vypis:=okno.k_subor;
    end;
 
  if keypressed then begin
     ch:=readkey;
     writexy_s(okno.xh,kurx,okno.yh+kury,d_attr,okno.o_full,okno.k_subor);
     k_vypis:=NIL;
     if ch=#13 then press_enter(kurx,kury,@okno);
     if (ch in [#48,#49,#50,#51,#52,#53,#54,#55,#56]) then begin
         old_file:=okno.k_subor^.meno_kon;
         okno.sort:=ord(ch)-48;
         sortuj(okno.sort);
         okno.p_subor:=okno.subor;
         vypis_o(okno.p_subor,old_file,kurx,kury);
        end;
 
     if (ch='-') then begin
         okno.o_full:=brief;
         text_okno(okno.o_full);
         vypis_o(okno.p_subor,old_file,kurx,kury);
        end;
 
     if (ch='=') then begin
         okno.o_full:=full;
         text_okno(okno.o_full);
         vypis_o(okno.p_subor,old_file,kurx,kury);
        end;
 
     if alt_akt then begin
        ch:=readkey;
        if (ch in [#16..#50,#120..#131]) then begin
        inc(alti);
        if (ch>#119) then old_file[alti]:=mapa_kl[ord(ch)-119]
                     else old_file[alti]:=mapa_kl[ord(ch)];
        pom:=okno.k_subor;
        po_subor:=pom;i:=0;
        while ( (po_subor^.zani<>po_subor) and
                (UUpCase(copy(po_subor^.meno_kon,1,alti))<>copy(old_file,1,alti) )) do begin
                 inc(i);
                 po_subor:=po_subor^.zani;
                end;
            if (UUpCase(copy(po_subor^.meno_kon,1,alti))=copy(old_file,1,alti) ) then begin
                for i:=i downto 1 do si_dole(kurx,kury);
                writexy(0,23,d_attr,copy(old_file,1,alti)+nothing(13-alti));
               end
              else dec(alti);
        end;
       end
       else begin
         alti:=0;
         writexy(0,23,d_attr,nothing(13));
        end;
 
     if ch=#0 then begin
        ch:=readkey;
        case ch of
           #72: si_hore(kurx,kury);                 { sipka hore }
           #80: si_dole(kurx,kury);                 { sipka dole }
           #81: for i:=1 to okno.poccel do          { Pg Dn }
                    si_dole(kurx,kury);
           #73: for i:=1 to okno.poccel do          { Pg Up }
                    si_hore(kurx,kury);
           #77: for i:=1 to okno.pocy do            { sipka vpravo }
                    si_dole(kurx,kury);
           #75: for i:=1 to okno.pocy do            { sipka vlavo }
                    si_hore(kurx,kury);
          end;
 
       end;
      if (p_vypis<>okno.p_subor) then vypis_o(okno.p_subor,okno.k_subor^.meno_kon,kurx,kury);
      p_vypis:=okno.p_subor;
    end
   else begin
     if mouse then begin
        get_mouse(x,y,but);
        if (but=1) and (uziv_obr[x,y]<>0) then begin
              show_mouse(false);
              if ((uziv_obr[x,y] shr 4)< 8) then begin
                  men_okno(uziv_obr[x,y] shr 4);
                  vypis_o(okno.p_subor,okno.k_subor^.meno_kon,kurx,kury);
                  k_vypis:=NIL;
                  show_mouse(true);
                 end                    { k if (uziv_obr .. }
               else begin
                    writexy_s(okno.xh,kurx,okno.yh+kury,d_attr,okno.o_full,okno.k_subor);
                    if ( (uziv_obr[x,y] shr 4)=8 ) then
                        si_hore(kurx,kury);                 { sipka hore }
 
                    if ( (uziv_obr[x,y] shr 4)=10 ) then
                        si_dole(kurx,kury);                 { sipka dole }
 
                                             { zisti na aky subor cvakol }
                    if ( (uziv_obr[x,y] shr 4)=9 ) then begin
                        okno.k_subor:=okno.p_subor;
                        i:=1;kury:=1;kurx:=0;
                        if (okno.o_full=full) then x:=trunc((x-okno.xh-1)/38)
                                              else x:=trunc((x-okno.xh-1)/13);
                        y:=y-okno.yh-1;
                        while not(((kurx=x) and (kury=y)) or (okno.k_subor^.zani=okno.k_subor) ) do
                              begin
                               inc(i);inc(kury);
                               if (kury>okno.pocy) then begin
                                  kury:=1;inc(kurx);
                                 end;
                               okno.k_subor:=okno.k_subor^.zani;
                              end;
                        no_mouse;
                        delay(100);
                        get_mouse(x,y,but);
                        if (but=1) then
                           press_enter(kurx,kury,@okno);
                       end;   { k if (uziv_obr[x,y] shr 4)=9 .. }
 
                  no_mouse;
                  if (p_vypis<>okno.p_subor) then vypis_o(okno.p_subor,okno.k_subor^.meno_kon,kurx,kury);
                      p_vypis:=okno.p_subor;
                end;           { k else }
 
              show_mouse(true);
           end;                { if (but=1) ... }
         end;                  { if mouse }
     rezidenty;                { rezidentne programi, ako hodinky atd.. }
    end;                       { k hlavnemu else }
 until ((ch=#27) or (but=2));
end;
 
begin
 textcolor(yellow);textbackground(blue);
 clrscr;
 d_attr:=7712;
 for x:=1 to 80 do              { znuluj uziv obrazovku }
     for y:=1 to 25 do uziv_obr[x,y]:=0;
 okno.pole_okna:=init_okna;             { inicializuje miesto pre okna }
 okno.cesta:='';
 okno.c_okna:=1;okno.subor:=NIL;okno.sort:=1;
 okno.subor:=napln_f('*.*',AnyFile-VolumeID,okno.pocet);
 sortuj(okno.sort);
 okno.xh:=8;okno.yh:=3;
 okno.xd:=69;okno.yd:=19;
 okno.c_okna:=1;okno.attr:=d_attr;okno.o_full:=full;
 okno.p_subor:=okno.subor;
 okno.k_subor:=okno.subor;
 gotoxy(1,24);
 urobpole(okno.xh,okno.xd,okno.yh,okno.yd,okno.pole_okna);
                                        { vezme im podklad }
 vepo_podkl(okno.xh,okno.xd,okno.yh,okno.yd,okno.pole_okna,true);
 text_okno(okno.o_full);
 mouse:=mouse_ok;
 vypis_o(okno.p_subor,okno.k_subor^.meno_kon,x,x);
 v_okno(okno.subor);
 vepo_podkl(okno.xh,okno.xd,okno.yh,okno.yd,okno.pole_okna,false);
 uvolni_mpole(okno.pole_okna);
 show_mouse(true);
 uvolni_f(okno.subor);
 uvolni_inokna(okno.pole_okna);
end.