home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ECO30603.ZIP / ECO30603.LZH / ECOLIBII / DEMOS / DEMO_FCS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-03-03  |  10.3 KB  |  391 lines

  1. {$A-,B-,D-,E-,F-,I-,L-,N-,O-,R-,S-,V-}
  2. {$M 65520, 0, 655360}
  3. uses
  4.   crt, dos, eco_lib,
  5.   eco_file, eco_tree,
  6.   eco_swap
  7.  
  8.   ;
  9.  
  10.  
  11.  
  12. const
  13.   nr_of_filekeys = 3;
  14.   nr_of_treekeys = 3;
  15.  
  16.   einde         : boolean = false;
  17.   pathprompt    : boolean = false;
  18.   filesonly     : boolean =  true;
  19.   startwithtree : boolean =  true;
  20.  
  21.  
  22.   filesretkeys : array[1..nr_of_filekeys] of word = (
  23.     _c_r { reread files }, _enter { action on file or dir }, _c_p { full }
  24.   );
  25.   rets : array[1..nr_of_treekeys] of word = (
  26.     _space, { pad } _c_r, { treescan } _enter { confirmation }
  27.   );
  28.  
  29.  
  30.  
  31. {tree}var
  32.   buf          : array[1..4096] of char;
  33.   oup          :                   text;
  34.   checkdriv    :                   char;
  35.   retkey,
  36.   i, j         :                   word;
  37.   call_editor,
  38.   commandline,
  39.   st           :                 string;
  40.   tmpscn,
  41.   backscreen   :           _scnimageptr;
  42.  
  43.   tree         :           treepanelobj;
  44.   files        :          filespanelobj;
  45.  
  46.  
  47.  
  48.  
  49.   procedure init_commander;
  50.   var
  51.     ch,
  52.     swch : char;
  53.   var
  54.     st,
  55.     environment_str : string;
  56.  
  57.   begin
  58.     call_editor := 'ECO.COM';
  59.     environment_str := __up(getenv('FCS_COMMANDER')); swch := '/';
  60.     if environment_str <> '' then begin
  61.       if __checkstr(swch + 'EDIT', environment_str, i, j) then begin
  62.         call_editor := __part(environment_str, i, j)
  63.       end;
  64.       if __checkstr(swch + 'TREE', environment_str, i, j) then
  65.         startwithtree := true;
  66.       if __checkstr(swch + 'FILE', environment_str, i, j) then
  67.         startwithtree := false;
  68.       if __checkstr(swch + 'PROMPT', environment_str, i, j) then
  69.         pathprompt := true;
  70.       if __checkstr(swch + 'SORT', environment_str, i, j) then begin
  71.         st := __part(environment_str, i, i);
  72.         ch := upcase(st[1]);
  73.         with files do case ch of
  74.           'E': sort := 2;
  75.           'D': sort := 3;
  76.           'S': sort := 4;
  77.           else sort := 1;
  78.         end;
  79.       end;
  80.     end;
  81.   end;
  82.  
  83.  
  84.  
  85.   procedure putfileopts;
  86.   begin
  87.     with files do setoptions(
  88.       { fulwide }  false,
  89.       { showpath } true,
  90.       { boxtype }  0,
  91.       54, 1, 80, 23,
  92.       06, { panel_f,   }    00, { panel_b,    }
  93.       15, { header_f,  }    00, { header_b,   }
  94.       15, { footer_f,  }    00, { footer_b,   }
  95.       true,
  96.       50, 5, 70, 9,
  97.       00, { popup_f,    }   07, { popup_b,    }
  98.       15, { tagnocsr_f, }   00, { tagnocsr_b, }
  99.       15, { tagcsr_f,   }   07, { tagcsr_b,   }
  100.       00, { scrollbar_f,}   07, { scrollbar_b,}
  101.       06, { curactbar_f,}   08  { curactbar_b }
  102.     );
  103.   end;
  104.  
  105.  
  106.  
  107.   procedure initfilespanel;
  108.   begin
  109.     with files do begin
  110.       newfiloff := true; init; putfileopts; readfiles(__curdir); startsorting;
  111.       { if not really altered by child process, that is: }
  112.       {retagfiles(readconfig, @tempfiltagar);} { pointer to array of booleans }
  113.       putfileopts;
  114.     end;
  115.   end;
  116.  
  117.  
  118.  
  119.   procedure showbackscreen;
  120.   var
  121.     tmpscn : _scnimageptr;
  122.   begin
  123.     new(tmpscn); __savscn(tmpscn);
  124.     __resscn(backscreen);
  125.     __retkey;
  126.     __resscn(tmpscn); dispose(tmpscn);
  127.   end;
  128.  
  129.  
  130.   procedure execprog(progn: string);
  131.   const
  132.     swaploc : array[boolean] of string[7] = ('on disk', 'in EMS');
  133.   var
  134.     status :         word;
  135.  
  136.   begin
  137.     useemsifavailable := true;
  138.     if not initexecswap(heapptr, 'SWAP.$$$') then begin
  139.       writeln('Unable to allocate swap space.');
  140.     end else begin
  141.       {write('Allocated ', bytesswapped, ' bytes ', swaploc[emsallocated]);}
  142.       __savscn(tmpscn);
  143.       __resscn(backscreen);
  144.       gotoxy(1, 25); write('(' + __slashfil(__curdir) + ') ' + progn);
  145.       clreol; writeln;
  146.       swapvectors;
  147.       status := execwithswap(getenv('COMSPEC'), ' /C ' + progn);
  148.       swapvectors;
  149.       writeln;
  150.       __savscn(backscreen);
  151.       {writeln('Exec status: ', status);}
  152.       shutdownexecswap;
  153.       __resscn(tmpscn);
  154.     end;
  155.   end;
  156.  
  157.  
  158.  
  159.   procedure __exec_commandline;
  160.   var edit : _editctrl;
  161.   begin
  162.     with edit do begin
  163.       _viewx1 := length(__curdir) + 4;
  164.       _viewx2 := 80;
  165.       _viewy1 := _currows;
  166.       _vscnfore := brown;
  167.       _vscnback := black;
  168.       _vscncols := 127;
  169.       _showflags := false;
  170.       _mask := '';
  171.     end;
  172.     if __editline(commandline, edit) then begin
  173.       execprog(commandline); commandline := ''
  174.     end;
  175.   end;
  176.  
  177.  
  178.  
  179.   procedure dofilespanel;
  180.   begin
  181.     with files do begin
  182.       repeat
  183.         retkey := $00;
  184.         st := walk_files_(
  185.           @filesretkeys, nr_of_filekeys, filesonly, retkey
  186.         );
  187.         if ((retkey = _enter) or (retkey = _padenter)) then begin
  188.           if (
  189.             (filarray^[filescursor].attr and directory) > 0
  190.           ) then begin
  191.             chdir(filarray^[filescursor+filoff].name);
  192.             readfiles(__curdir); startsorting; filoff := 0; filescursor := 0;
  193.             newfiloff := false;
  194.             with tree do begin
  195.               tree.jump_curpath; newtreeoff := true; tree.draw
  196.             end;
  197.             _doscurpath := __curdir;
  198.             draw;
  199.           end else begin
  200.             if __comp(
  201.               __extractext(filarray^[filescursor+filoff].name), 'pas'
  202.             ) then execprog('T ' + filarray^[filescursor+filoff].name);
  203.             if __comexebatcmdfilter(
  204.               filarray^[filescursor+filoff].name
  205.             ) then execprog(filarray^[filescursor+filoff].name)
  206.           end;
  207.         end;
  208.  
  209.         if retkey = _f3 then execprog(
  210.           'FCV ' + filarray^[filescursor+filoff].name
  211.         );
  212.  
  213.         if retkey = _f4 then begin
  214.           execprog(
  215.             call_editor + ' ' + filarray^[filescursor+filoff].name
  216.           );
  217.           readfiles(__curdir);
  218.         end;
  219.  
  220.       until (
  221.         (retkey = _a_q) or (retkey = _tab) or (retkey =_c_o) or
  222.         (retkey = _backquote)
  223.       );
  224.     end; { with }
  225.   end;
  226.  
  227.  
  228.  
  229.   procedure puttreeopts;
  230.   begin
  231.    with tree do begin
  232.       setoptions(
  233.         { auto }   false,
  234.         { wide }   false,
  235.         { path }   true,
  236.         { boxt }   0,
  237.         { xyxy }   1, 1, 53, 23,
  238.         { panl }   6, black,
  239.         { head }   yellow, black,
  240.         { foot }   yellow, black,
  241.         { scan }   true,
  242.         { xyxy }   31, 10, 49, 11,
  243.         { popu }   black, lightgray,
  244.         { tgno }   black, lightgray,
  245.         { tgcs }   lightblue, black,
  246.         { tgsc }   black, lightgray,
  247.         { curr }   brown, darkgray
  248.       );
  249.     end;
  250.   end;
  251.  
  252.  
  253.   procedure inittreepanel;
  254.   begin
  255.     st := getenv('WTREEINFO');
  256.     if st = '' then st := __curdir;
  257.     checkdriv := upcase(st[1]);
  258.     with tree do begin
  259.       init; putdefaults; puttreeopts;
  260.       st := __curdir;
  261.       drivechar := upcase(st[1]);
  262.       horspace := '  '; horbar := '──';
  263.       {writeln(checkdriv + treeinfofile + drivechar);}
  264.       __savscn(scn1);
  265.       if (paramstr(1)='/r') or not(__existfil(
  266.         checkdriv + treeinfofile + drivechar)
  267.       ) then begin
  268.         __bandwin(true, 25, 9, 55, 12, 0, 7, sh_default, 0); trace_tree;
  269.         save_tree(checkdriv + treeinfofile + drivechar);
  270.       end else begin
  271.         load_tree(checkdriv + treeinfofile + drivechar);
  272.       end;
  273.       build_tree(false); jump_curpath;
  274.     end;
  275.   end;
  276.  
  277.  
  278.  
  279.  
  280.   procedure dotreepanel;
  281.   var s : string;
  282.   begin
  283.     with tree do begin
  284.       repeat
  285.         retkey := 0;
  286.         s := walk_tree_(@rets, nr_of_treekeys, retkey);
  287.  
  288.         if retkey = _c_e then begin
  289.           assign(oup, 'tree.'+drivechar); rewrite(oup); settextbuf(oup, buf);
  290.           for i := 0 to nodenumber-1 do writeln(oup, '   ' + nodedispptr^[i]);
  291.           close(oup);
  292.         end;
  293.  
  294.          if retkey = _c_c then begin
  295.            jump_curpath; draw;
  296.          end;
  297.  
  298.         if retkey = _c_p then begin
  299.           widetree := not widetree; build_tree(true); newtreeoff := true;
  300.           draw;
  301.         end;
  302.  
  303.         if retkey = _c_f6 then increase_bar;
  304.  
  305.         if retkey = _c_f5 then decrease_bar;
  306.  
  307.         if retkey = _enter then begin
  308.           if (
  309.             __existpath(__backrem(__normfil(trace_path(walkcsr)))) or
  310.             (__lastchr(__backrem(__normfil(s))) in _slashset) 
  311.             { backrem chops only trailing slashes from nonroot directories }
  312.           ) then begin
  313.             if (
  314.               __lastchr(__backrem(__normfil(s))) in _slashset
  315.             ) then chdir('\') else chdir(
  316.               __backrem(__normfil(trace_path(walkcsr)))  { no slash on end }
  317.             );
  318.             _doscurpath := __curdir;
  319.           end else begin
  320.             newtreeoff := true;
  321.             walkoffset := 0; walkcsr := 0;
  322.             trace_tree; save_tree(treeinfofile);
  323.             build_tree(true); chdir(drivechar+':\');
  324.             retkey := 0;
  325.           end;
  326.           with files do begin
  327.             readfiles(__curdir); startsorting; filoff := 0; filescursor := 0;
  328.             newfiloff := true; draw;
  329.           end;
  330.         end;
  331.       until (
  332.         (retkey=_enter) or (retkey=_tab) or (retkey=_a_q) or (retkey =_c_o) or
  333.         (retkey = _backquote)
  334.       );
  335.     end;
  336.   end;
  337.  
  338.  
  339.  
  340.   procedure showpanels;
  341.   begin
  342.     tree.draw; files.draw;
  343.   end;
  344.  
  345.  
  346.  
  347. type
  348.   paneltype =(nopanel, treepanel, filespanel, infopanel);
  349.  
  350.  
  351. var
  352.   panel : paneltype;
  353.  
  354.  
  355. begin
  356.   __stdio; __cls; gotoxy(1, 25);  init_commander;
  357.   writeln('The Fast Commander :: An Add-on Demo V 3.51.');
  358.   write(
  359.     'The ECO Library II Release 3.0  Version ',
  360.     '6.02 Concise Edition - Pascal Port #2.'
  361.   );
  362.   if backscreen = nil then new(backscreen); __savscn(backscreen); new(tmpscn);
  363.   inittreepanel; initfilespanel; showpanels;
  364.   if startwithtree then panel := treepanel else panel := filespanel;
  365.  
  366.   retkey := __retkey; __clrscn(1, 24, 80, 25, 7, 0,' ');
  367.   gotoxy(1, 25);
  368.   if pathprompt then begin
  369.     gotoxy(length(__curdir) + 4, 25);
  370.     __write(1, 25, 7, 0, '(' + __slashfil(__curdir) + ') ');
  371.   end;
  372.  
  373.   repeat
  374.     case panel of
  375.       filespanel: begin tree.draw; files.draw; dofilespanel end;
  376.       treepanel : begin files.draw; tree.draw; dotreepanel end;
  377.     end;
  378.     if retkey = _tab then begin
  379.       if panel = filespanel then
  380.         panel := treepanel else
  381.         panel := filespanel;
  382.     end;
  383.     if retkey = _a_q then einde := true;
  384.     if retkey = _c_o then showbackscreen;
  385.     if retkey = _backquote then __exec_commandline;
  386.     retkey := $0000;
  387.   until einde;
  388.  
  389.   __resscn(backscreen); dispose(backscreen); dispose(tmpscn);
  390. end.
  391.