home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ECO30603.ZIP / ECO30603.LZH / ECOLIBCS / DEMOS / W.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-03-08  |  45.2 KB  |  1,485 lines

  1. {$F+}
  2. {$M 65520,0,655360}
  3. uses
  4.   eco_lib, dos, crt
  5.  
  6.   ; 
  7.  
  8.  
  9.  
  10. const
  11.   max_colours = 30;
  12.   
  13.  
  14. type
  15.   attr_colours_type = record
  16.     ext    : string[3];
  17.     colour :      byte;
  18.   end;
  19.   attr_colours_type_ar = array[0..max_colours] of attr_colours_type;
  20.  
  21.  
  22. const
  23.   attr_colours: attr_colours_type_ar = (
  24.     (ext : 'dir'; colour : red),            { directory }
  25.     (ext : 'vol'; colour : magenta),        { volumeid  }
  26.     (ext : 'inf'; colour : darkgray),       { infolines }
  27.     (ext : 'std'; colour : lightgray),      { doscolour }
  28.  
  29.     (ext : 'exe'; colour : yellow),
  30.     (ext : 'com'; colour : yellow),         { executables }
  31.     (ext : 'bat'; colour : yellow),
  32.     (ext : 'cmd'; colour : yellow),
  33.  
  34.     (ext : 'asm'; colour : lightcyan),
  35.     (ext : 'ash'; colour : lightcyan),
  36.     (ext : 'pas'; colour : lightcyan),
  37.     (ext : 'c';   colour : lightcyan),      { sources }
  38.     (ext : 'cpp'; colour : lightcyan),
  39.     (ext : 'h';   colour : lightcyan),
  40.     (ext : 'prg'; colour : lightcyan),
  41.     (ext : 'inc'; colour : lightcyan),
  42.  
  43.     (ext : 'arc'; colour : lightred),
  44.     (ext : 'arj'; colour : lightred),
  45.     (ext : 'lzh'; colour : lightred),       { archives }
  46.     (ext : 'zip'; colour : lightred),
  47.     (ext : 'zoo'; colour : lightred),
  48.  
  49.     (ext : 'txt'; colour : magenta),
  50.     (ext : 'doc'; colour : magenta),
  51.     (ext : 'sam'; colour : magenta),        { textfiles }
  52.     (ext : 'inf'; colour : magenta),
  53.     (ext : 'hlp'; colour : magenta),
  54.  
  55.     (ext : 'tpu'; colour : brown),
  56.     (ext : 'obj'; colour : brown),          { binaries }
  57.     (ext : 'lib'; colour : brown),
  58.  
  59.     (ext : 'ini'; colour : white),          { initialisations }
  60.     (ext : 'cfg'; colour : white)
  61.   );
  62.  
  63.   packsize           : byte    =        21;
  64.  
  65.   use_colours        : boolean =      true;
  66.   nopointsdir        : boolean =      true;
  67.  
  68.   maxoverdrive       : boolean =     false;
  69.   ampm               : boolean =     false;
  70.   debug              : boolean =     false;
  71.   extended           : boolean =     false;
  72.  
  73.   show_date          : boolean =      true;
  74.   show_pad           : boolean =      true;
  75.   show_drv           : boolean =      true;
  76.   show_num           : boolean =      true;
  77.   show_sum           : boolean =      true;
  78.   greatness          : boolean =     false;
  79.   freespace          : boolean =      true;
  80.  
  81.   dir_report         : boolean =     false;
  82.   globaltree         : boolean =     false;
  83.   interrupted        : boolean =     false;
  84.   kind               : sortmethods = on_name;
  85.   noscan             : boolean =     false;
  86.   not_sum_only       : boolean =      true;
  87.   sort_items         : boolean =      true;
  88.   takemainsize       : boolean =     false;
  89.   upcasenames        : boolean =     false;
  90.   wide               : boolean =     false;
  91.   comexebatcmdfilter : boolean =     false;
  92.  
  93.   normalcolour       : byte    = lightgray;
  94.  
  95.  
  96.   condition_attrs : condition_attrstype = (
  97.     show_r_o    :   true;
  98.     show_hid    :   true;
  99.     show_sys    :   true;
  100.     show_arc    :   true;
  101.     show_vol    :   true;
  102.     show_dir    :   true;
  103.     show_non    :   true;
  104.     sort_method : on_name
  105.   );
  106.  
  107.  
  108.  
  109.  
  110. var
  111.   originalswitch, 
  112.   swch             :            char;
  113.   filarray         : filarraytypeptr;
  114.   findattribute,
  115.   max_colours_env,
  116.   manipulate       :            word;
  117.   sort_ptr,
  118.   attr_ptr         :         pointer;
  119.   i, j, coll,
  120.   plus, cols,
  121.   skind, nod,
  122.   mainsize,
  123.   totlin,
  124.   dirs, numitems   :            word;
  125.   volum, redirect  :         boolean;
  126.   env, tmp,
  127.   st, st2,
  128.   colour_string,
  129.   treeinfosource,
  130.   olddospath       :          string;
  131.   tot              :         longint;
  132.   oldexitproc      :         pointer;
  133.  
  134.  
  135.  
  136.   procedure toggle(var b: boolean);
  137.   begin
  138.     b := not b;
  139.   end;
  140.  
  141.  
  142.   function __rempoint(s: string): string;
  143.   var i : byte;
  144.   begin
  145.     i := pos('.', s);
  146.     if i > 0 then delete(s, i, 1);
  147.     __rempoint := s;
  148.   end;
  149.  
  150.  
  151.   procedure textcolour(b: byte);
  152.   begin
  153.     if use_colours then textcolor(b);
  154.   end;
  155.  
  156.  
  157.   function redirectpressed: boolean;
  158.   begin
  159.     redirectpressed := not(redirect) and keypressed;
  160.   end;
  161.  
  162.  
  163.  
  164. {▒▒subtree functions▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒}
  165. const
  166.   maxnodes = 3072;
  167.  
  168. type
  169.   srec_ptr = ^srec_chain;
  170.   srec_chain = record
  171.     srec : searchrec;
  172.     bid  :   longint;
  173.     prev :      word;
  174.     link :  srec_ptr;
  175.   end;
  176.  
  177.   nodes = record
  178.     name    : string[12];
  179.     bid     :    longint; { bytes in directory }
  180.     parent  :       word;
  181.   end;
  182.  
  183.   nodearraytype = array[0..maxnodes] of nodes;
  184.   nodearraytypeptr = ^nodearraytype;
  185.  
  186. const
  187.   x3                : byte    =                1;
  188.   x4                : byte    =               12;
  189.   y3                : byte    =                1;
  190.   popup_f           : byte    =                7;
  191.   popup_b           : byte    =                0;
  192.   sizedir           : boolean =             true;
  193.   showscan          : boolean =             true;
  194.   drivechar         : char    =              'C';
  195.   treeinfodrivechar : char    =              'C';
  196.   treeinfofile      : string  =  ':\TREEINFO.DR';
  197.   totgen            : longint =                0;
  198.   totnum            : longint =                0;
  199.  
  200.  
  201. var
  202.   node_file              :    file of nodes;
  203.   nodearray              : nodearraytypeptr;
  204.   prevparent,
  205.   nodenumber             :             word;
  206.   srec                   :        searchrec;
  207.   searchbasis,
  208.   searchpattern,
  209.   searchpath,
  210.   s                      :           string;
  211.  
  212.  
  213.   function trace_path(temphead: integer): pathstr;
  214.   var
  215.     off      :                    word;
  216.     st       :                  string;
  217.     i        :                    word;
  218.     tmp      : array[1..50] of integer;
  219.  
  220.   begin
  221.     off := 0;
  222.     while temphead>0 do begin
  223.       inc(off); tmp[off] := temphead;
  224.       temphead := nodearray^[temphead].parent;
  225.     end; st := '\';
  226.     if off>0 then for i := off downto 1 do
  227.       st := st + nodearray^[tmp[i]].name +'\';
  228.     off := 0; fillchar(tmp, sizeof(tmp), chr(48));
  229.     trace_path := st;
  230.   end;
  231.  
  232.  
  233.  
  234.   function calccurpath(var notfound: boolean): word;
  235.   var
  236.     i,j      :    word;
  237.     curpath  : pathstr;
  238.     chops    :  string;
  239.  
  240.   begin
  241.     getdir(0, curpath); notfound := false;
  242.     if length(curpath) = 3 then calccurpath := 0 else begin
  243.       curpath := __cvtstr(curpath + '\', _to_upcase_str);
  244.       i := length(curpath)-1; j := i; while curpath[i]<>'\' do dec(i); inc(i);
  245.       chops := __cvtstr(copy(curpath, i, j-i+1), _to_upcase_str);
  246.  
  247.       j := 0;
  248.       for i := nodenumber - 1 downto 1 do if
  249.         __cvtstr(nodearray^[i].name, _to_upcase_str)=chops then
  250.         if __cvtstr(__normfil(trace_path(i)),_to_upcase_str)=curpath then j :=i;
  251.       if j=0 then notfound := true;
  252.       calccurpath := j;
  253.     end;
  254.   end;
  255.  
  256.  
  257. {$I-}
  258.   procedure showtree(s: string);
  259.   begin
  260.     if not redirect then begin gotoxy(19, wherey); write(s) end;
  261.   end;
  262.  
  263.  
  264.   procedure search_tree(level: word);
  265.   var
  266.     i         :  integer;
  267.     s         :   string;
  268.     srec_root,
  269.     srec_link : srec_ptr;
  270.  
  271.     { not much subdirs in one dir, so no efficiency taken into account }
  272.     procedure sort(srec_root: srec_ptr);
  273.     var
  274.       srec1, srec2, srec3 :  srec_ptr;
  275.       srec                : searchrec;
  276.  
  277.     begin
  278.       srec1 := srec_root;
  279.       while srec1^.link <> nil do begin
  280.         srec2 := srec1^.link; srec3 := srec1;
  281.         repeat { assume we are already sorted properly }
  282.           if srec2^.srec.name < srec3^.srec.name then srec3 := srec2;
  283.           srec2 := srec2^.link;
  284.         until srec2 = nil;
  285.         if srec3 <> srec1 then begin
  286.           srec := srec1^.srec; srec1^.srec := srec3^.srec; srec3^.srec := srec;
  287.         end; srec1 := srec1^.link;
  288.       end;
  289.     end;
  290.  
  291.   begin
  292.     srec_root := nil;
  293.     if sizedir then findfirst('*.*', anyfile, srec) else findfirst(
  294.       '*.*', directory, srec
  295.     );
  296.  
  297.     nodearray^[nodenumber].bid := 0;
  298.     while doserror=0 do begin {@}
  299.       if not({__nonascii(srec.name) or }((srec.attr and directory)=0)) then begin
  300.         if sizedir then inc(
  301.           nodearray^[nodenumber].bid, __main(srec.size, mainsize)
  302.         );
  303.         if (((srec.attr and directory)>0) and (srec.name[1] <> '.')) then begin
  304.           if srec_root = nil then begin
  305.             new(srec_root); srec_link := srec_root;
  306.           end else begin
  307.             new(srec_link^.link); srec_link := srec_link^.link;
  308.           end; srec_link^.srec := srec; srec_link^.link := nil;
  309.           srec_link^.prev := prevparent;
  310.         end;
  311.       end;
  312.       findnext(srec);
  313.     end; inc(prevparent);
  314.     if srec_root <> nil then begin
  315.       if sort_items then sort(srec_root);
  316.       if showscan then showtree('\');
  317.       repeat
  318.         s := srec_root^.srec.name;
  319.         with nodearray^[nodenumber] do begin
  320.           name := s; parent := srec_root^.prev;
  321.         end;
  322.         if nodenumber < maxnodes then inc(nodenumber) else
  323.           maxoverdrive := true;
  324.         if showscan then showtree(
  325.           __juststr(__num(nodenumber), '0', 3, _right_just_str) + ' : ' +
  326.           __juststr(s, ' ', 12, _left_just_str)
  327.         );
  328.         chdir(s); search_tree(level+1); chdir('..');
  329.         srec_link := srec_root; srec_root := srec_root^.link;
  330.         dispose(srec_link);
  331.       until (srec_root = nil); {@}
  332.     end else if (level = 0) and showscan then showtree('No <DIR> entries');
  333.   end; { search_tree }
  334.  
  335.  
  336.  
  337.   procedure trace_tree;
  338.   var oldpath: string;
  339.   begin
  340.     s := ''; nodenumber := 1; prevparent := 0; new(nodearray);
  341.     getdir(0, oldpath); 
  342.     showscan := _dosdiscsize > 50000000; { > 50.000.000 }
  343.     search_tree(0); chdir(oldpath);
  344.     gotoxy(16, wherey); clreol; writeln(':  ', nodenumber);
  345.     if maxoverdrive then begin
  346.       writeln;
  347.       writeln(
  348.         'WARNING: limited tree functionality: more than ',
  349.         maxnodes, ' directories!'
  350.       );
  351.     end;
  352.   end;
  353.  
  354.  
  355.   procedure load_tree(fname: pathstr);
  356.   var rec : searchrec;
  357.   begin
  358.     s := ''; nodenumber := 1; prevparent := 0; new(nodearray);
  359.     assign(node_file, fname); reset(node_file);
  360.     while not(eof(node_file)) do begin
  361.       read(node_file, nodearray^[nodenumber]); inc(nodenumber)
  362.     end; close(node_file);
  363.     nodearray^[0].bid := 0;
  364.   end;
  365.  
  366.   procedure save_tree(fname: pathstr);
  367.   var rec : searchrec;
  368.   begin
  369.     assign(node_file, fname); rewrite(node_file);
  370.     for nod := 1 to nodenumber-1 do write(node_file, nodearray^[nod]);
  371.     close(node_file);
  372.   end;
  373.  
  374. {▒▒subtree functions▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒}
  375.  
  376.  
  377.   
  378.  
  379.  
  380.   procedure help;
  381.  
  382.     procedure s(s: string);
  383.     var
  384.       part1, part2 : string;
  385.       i, j         :   byte;
  386.  
  387.     begin
  388.       i := pos(swch, s);
  389.       j := i;
  390.       while (j < length(s)) and not(s[j] in ['[', ' ']) do inc(j);
  391.       if s[2] = '.' then begin i := 2; j := 3 end;
  392.       if (i < 7) and (i > 0) then begin
  393.         part1 := __part(s, 1, i-1);
  394.         part2 := __part(s, j, length(s));
  395.         write(part1);
  396.         textcolour(lightred);
  397.         write(__part(s, i, j-1));
  398.         textcolour(yellow);
  399.         write(part2);
  400.       end else write(s);
  401.       clreol;
  402.       writeln;
  403.     end;
  404.  
  405.   begin
  406.     textcolour(yellow);
  407.     s('');
  408.     s('');
  409.     s(
  410.       ' · ·· · ··  ─── ─ ─  ──  ┌─────────────' +
  411.       '───────────────────────────────────────┐'
  412.     );
  413.     s(
  414.       '· ·  ── · ─ ─  ─   ── ── │ (W) MCMXCIII' +
  415.       ' UltiHouse Software / This is freeware │'
  416.     );
  417.     s(
  418.       '  ·· ·─ ─ ── ·· ─ ── ·   └─────────────' +
  419.       '───────────────────────────────────────┘'
  420.     );
  421.     s('');
  422.     s(
  423.       'Usage: ' + __progname + '  {filepathspec}  [options]'
  424.     );
  425.     s(
  426.       '  Notes: Forward slashes may be used instead of backslashes.'
  427.     );
  428.     s(
  429.       '  If a directory is designated, using forward slashes (/), that'
  430.     );
  431.     s(
  432.       '  matches an attribute skipper, use double slashes like in //a or //s'
  433.     );
  434.     s(
  435.       '  Options are toggles: set in environment WDIR ' +
  436.       'and commandline will toggle.'
  437.     );
  438.     s(
  439.       ' ' + swch + 
  440.       'switch c :: where `c'' is a char for switch designation' +
  441.       ' (environment)'
  442.     );
  443.     if swch <> '-' then s(
  444.       '  Suggested environment: "SET WDIR=-switch ' + swch +
  445.       ' ' + swch + 'w ' + swch + 'u 1 ' + swch + 'x ' + swch +
  446.       'k"  en   "SET WTREEINFO=C"'
  447.     ) else s(
  448.       '  Suggested environment: "SET WDIR=' + swch + 'w ' + swch + 'u 1 ' + 
  449.       swch + 'x ' + swch + 'k"  en   "SET WTREEINFO=C"'
  450.     );
  451.     s('');
  452.     s(
  453.       ' ' + swch + 'A[rchive]    :: Skip Archive files.'
  454.     );
  455.     s(
  456.       ' ' + swch + 'B[oot/Sys]   :: Skip Boot / System files.' +
  457.       '     ┌───┐ ┌─┬─┐ ┌─┬─┐ ┌───┐'
  458.     );
  459.     s(
  460.       ' ' + swch + 'H[idden]     :: Skip Hidden files.' +
  461.       '            ├───┤   │     │   ├──┬┘'
  462.     );
  463.     s(
  464.       ' ' + swch + 'R[eadonly]   :: Skip ReadOnly files.' +
  465.       '          ┴   ┴   ┴     ┴   ┴  └─'
  466.     );
  467.     s(
  468.       ' ' + swch + 'N[one]       :: Skip files with no attributes.'
  469.     );
  470.     s('');
  471.     s('');
  472.     s(
  473.       ' ' + swch + 'E[xtension]  :: Sort files by extension.'
  474.       );
  475.     s(
  476.       ' ' + swch + 'L[ength]     :: Sort files by filelength.' +
  477.       '     ┌───┐ ┌───┐ ┌───┐ ┌─┬─┐'
  478.     );
  479.     s(
  480.       ' ' + swch + 'T[imedate]   :: Sort files by time and date.' +
  481.       '  └───┐ │   │ ├──┬┘   │  '
  482.     );
  483.     s(
  484.       ' ' + swch + 'V[erbose]    :: Sort files by filename.' +
  485.       '       └───┘ └───┘ ┴  └─   ┴  '
  486.     );
  487.     s(
  488.       ' ' + swch + 'Q Do not sort the files.' +
  489.       ' (Some OS''s like OS/2 V2.x will sort anyhow)'
  490.     );
  491.     if _currows >= 40 then s('');
  492.     if not(redirect) and (_currows < 40) then __delaykey(25000);
  493.     s('');
  494.  
  495.     s(
  496.       ' .  searches executables (COM EXE BAT CMD). ( Example:  w ../EXE/. )'
  497.     );
  498.     s(
  499.       ' ' + swch + '.            :: toggle the showing of . and .. directories.'
  500.     );
  501.     s(
  502.       ' ' + swch + 'n            :: Other date form (1 ≤ n ≤ 4).'
  503.     );
  504.     s(
  505.       ' ' + swch + 'C[olours]    :: Show colours (SET WCOLOURS=)  ' + 
  506.       '┌───┐ ┌───┐ ┌─┬─┐ ┬ ┌───┐ ┌┐  ┬'
  507.     );
  508.     s(
  509.       ' ' + swch + 'D[irectory]  :: Show <DIR> and discsize.      ' + 
  510.       '│   │ ├───┘   │   │ │   │ │└─┐│'
  511.     );
  512.     s(
  513.       ' ' + swch + 'F[ilesize]   :: Sum files and show disc size. ' + 
  514.       '└───┘ ┴       ┴   ┴ └───┘ ┴  └┘'
  515.     );
  516.     s(
  517.       ' ' + swch + 'G f|u|n|d|t|p:: Free-Used-Number-Drive-Total-Path Footer' +
  518.       ' construction.'
  519.     );
  520.     s(
  521.       ' ' + swch + 'I[nfo]       :: Show Post/Ante meridiane sign.'
  522.     );
  523.     s(
  524.       ' ' + swch + 'J            :: Show volume-lable or not.'
  525.     );
  526.     s(
  527.       ' ' + swch + 'M[ultiple N] :: Main of filesize (multiples of 512)'
  528.     );
  529.     s(
  530.       ' ' + swch + 'O[ther info] :: Show current date on commandline.'
  531.     );
  532.     s(
  533.       ' ' + swch + 'P[ause]      :: Do not wait every ' + __num(_currows) +
  534.       ' lines.'
  535.     );
  536.     s(
  537.       ' ' + swch + 'U n where n=1:: lowcase;  n=2: upcase;  n=0 (default):' +
  538.       ' OS filenames.'
  539.     );
  540.     s(
  541.       ' ' + swch + 'W[ide]       :: Show more files on screen.     '
  542.     );
  543.     s(
  544.       ' ' + swch + 'X[tended]    :: Information visible. (Numbered, long items)'
  545.     );
  546.     s(
  547.       ' ' + swch + 'Y            :: do not add linefeeds with redirection ' +
  548.       'to stdio.'
  549.     );
  550.     s(
  551.       ' ' + swch + 'Z            :: debugmode for a complete trace of actions.'
  552.     );
  553.     s(
  554.       ' ' + swch + 'S[ubtree]    :: Take entire subtree of directory.'
  555.     );
  556.     s(
  557.       '   ' + swch + 'K kill tree scan when scanning subdirectories' +
  558.       ' (only from root).'
  559.     );
  560.     s('');
  561.     s(
  562.       'Normally, you can use default colours. If you like, you can specify up' +
  563.       ' to ' + __num(max_colours-2));
  564.     s(   
  565.       'colours for extensions besides the first 4,' +
  566.       'reserved for <DIR> <VOL> <INF> <STD>'
  567.     );
  568.     s(
  569.       'SET WCOLOURS=DIR:4  VOL:3  INF:8  STD:7  ARC,ARJ,LZH,ZIP:14  EXE,ASM, ....'
  570.     );
  571.     write('Standard colours: ');
  572.     for i := 1 to max_colours+1 do 
  573.       if attr_colours[i].colour <> attr_colours[i-1].colour then begin
  574.         textcolour(attr_colours[i-1].colour); write(attr_colours[i-1].ext, ' ');
  575.         textcolour(normalcolour);
  576.       end;
  577.     exitproc := oldexitproc;
  578.     textcolour(normalcolour);
  579.     halt(255);
  580.   end; { help }
  581.  
  582.  
  583.  
  584.  
  585.  
  586.   procedure getparams;
  587.   const
  588.     show: array[boolean] of string[11] = ('Do not show', 'Show');
  589.     allow: array[boolean] of string[12] = ('Do not allow', 'Allow');
  590.     dont: array[boolean] of string[2] = ('No', 'Do');
  591.     mani: array[0..2] of string[9] = ('Unchanged', 'Lowered', 'Uppered');
  592.  
  593.   begin
  594.     if __checkstr(swch + 'switch', env, i, j) then begin
  595.       tmp := __nw(copy(env, i, j-i)); swch := tmp[1];
  596.       originalswitch := swch;
  597.     end;
  598.  
  599.     if __checkstr(swch + '.', env, i, j) then begin
  600.       toggle(nopointsdir);
  601.       if debug then writeln(
  602.         'Env: ', show[nopointsdir], ' the . and .. directories.'
  603.       );
  604.     end;
  605.     if __checkstr(swch + 'z', env, i, j) then begin
  606.       toggle(debug);
  607.       if debug then writeln(
  608.         '__DEBUG MODE ON__ Warning: environment debugmode!'
  609.       );
  610.     end;
  611.     if __checkstr(swch + '1', env, i, j) then begin
  612.       skind := 1;
  613.       if debug then writeln('Env: Eurodate set.');
  614.     end;
  615.     if __checkstr(swch + '2', env, i, j) then begin
  616.       skind := 2;
  617.       if debug then writeln('Env: American date set.');
  618.     end;
  619.     if __checkstr(swch + '3', env, i, j) then begin
  620.       skind := 3;
  621.       if debug then writeln('Env: Text date set.');
  622.     end;
  623.     if __checkstr(swch + '4', env, i, j) then begin
  624.       skind := 4;
  625.       if debug then writeln('Env: Full text date set.');
  626.     end;
  627.     if __checkstr(swch + 'a', env, i, j) then begin
  628.       toggle(condition_attrs.show_arc);
  629.       if debug then writeln(
  630.         'Env: ', show[condition_attrs.show_arc], ' Archive atrributed files.'
  631.       );
  632.     end;
  633.     if __checkstr(swch + 'b', env, i, j) then begin
  634.       toggle(condition_attrs.show_sys);
  635.       if debug then writeln(
  636.         'Env: ', show[condition_attrs.show_sys],
  637.         ' Boot/System attributed files.'
  638.       );
  639.     end;
  640.     if __checkstr(swch + 'c', env, i, j) then begin
  641.       if debug then writeln(
  642.         'Env: ', show[use_colours], ' colours.'
  643.       );
  644.       toggle(use_colours);
  645.     end;
  646.     if __checkstr(swch + 'd', env, i, j) then begin
  647.       toggle(dir_report);
  648.       if dir_report then findattribute := directory + only else
  649.         findattribute := anyfile;
  650.     end;
  651.     if __checkstr(swch + 'e', env, i, j) then begin
  652.       condition_attrs.sort_method := on_extension;
  653.       if debug then writeln('Env: Sort files on extension.');
  654.     end;
  655.  
  656.     if __checkstr(swch + 'f', env, i, j) then begin
  657.       toggle(not_sum_only);
  658.       if debug then writeln(
  659.         'Env: ', show[not_sum_only], ' summation of bytes.'
  660.       );
  661.     end;
  662.     if __checkstr(swch + 'h', env, i, j) then begin
  663.       toggle(condition_attrs.show_hid);
  664.       if debug then writeln(
  665.         'Env: ', show[condition_attrs.show_hid], ' Hidden attributed files.'
  666.       );
  667.     end;
  668.     if __checkstr(swch + 'i', env, i, j) then begin
  669.       toggle(ampm);
  670.       if debug then writeln('Env: ', show[ampm], ' AmPm designator.');
  671.     end;
  672.     if __checkstr(swch + 'j', env, i, j) then begin
  673.       if debug then writeln(
  674.         'Env: ', show[not condition_attrs.show_vol], ' volume-lable.'
  675.       );
  676.       toggle(condition_attrs.show_vol);
  677.     end;
  678.     if __checkstr(swch + 'k', env, i, j) then begin
  679.       toggle(noscan);
  680.       if debug then writeln('Env: Kill treescan for full volume, use file.');
  681.     end;
  682.     if __checkstr(swch + 'l', env, i, j) then begin
  683.       condition_attrs.sort_method := on_size;
  684.       if debug then writeln('Env: Sort files on size (fileLength).');
  685.     end;
  686.     if __checkstr(swch + 'm', env, i, j) then begin
  687.       takemainsize := true; extended := true;
  688.       mainsize := __str(__nw(copy(env, i, j-i)));
  689.       if debug then writeln('Env: Take mainsize in Kbytes.');
  690.     end;
  691.     if __checkstr(swch + 'n', env, i, j) then begin
  692.       if debug then writeln(
  693.         'Env: ', show[condition_attrs.show_non], ' unattributed files.'
  694.       );
  695.       toggle(condition_attrs.show_non);
  696.     end;
  697.     if __checkstr(swch + 'o', env, i, j) then begin
  698.       toggle(show_date);
  699.       if debug then writeln(
  700.         'Env: ', show[show_date], ' date as commandline header.'
  701.       );
  702.     end;
  703.     if __checkstr(swch + 'p', env, i, j) then begin
  704.       toggle(interrupted);
  705.       if debug then writeln('Env: ', allow[interrupted], ' interruption.');
  706.     end;
  707.  
  708.     if __checkstr(swch + 'q', env, i, j) then begin
  709.       toggle(sort_items);
  710.       if debug then writeln('Env: ', allow[sort_items], ' sorting files.');
  711.     end;
  712.     if __checkstr(swch + 'r', env, i, j) then begin
  713.       toggle(condition_attrs.show_r_o);
  714.       if debug then writeln(
  715.         'Env: ', show[condition_attrs.show_r_o], ' ReadOnly attributed files.'
  716.       );
  717.     end;
  718.     if __checkstr(swch + 's', env, i, j) then begin
  719.       toggle(globaltree);
  720.       if debug then writeln(
  721.         'Env: ', dont[globaltree], 'Scan subtree of current directory.'
  722.       );
  723.     end;
  724.     if __checkstr(swch + 't', env, i, j) then begin
  725.       condition_attrs.sort_method := on_datetime;
  726.       if debug then writeln('Env: Sort files on time and date.');
  727.     end;
  728.     if __checkstr(swch + 'u', env, i, j) then begin
  729.       manipulate := __str(__nw(copy(env, i, j-i)));
  730.       if debug then writeln(
  731.         'Env: The case is ', mani[manipulate],
  732.         '. (', i, ':', j, '|', copy(env, i, j-i), ')'
  733.       );
  734.       if manipulate = 2 then manipulate := _to_upcase_str else
  735.         if manipulate = 1 then manipulate := _to_lowcase_str else
  736.           manipulate := 0;
  737.     end;
  738.     if __checkstr(swch + 'v', env, i, j) then begin
  739.       condition_attrs.sort_method := on_name;
  740.       if debug then writeln('Env: Sort files verbosely (on name).');
  741.     end;
  742.     if __checkstr(swch + 'w', env, i, j) then begin
  743.       toggle(wide);
  744.       if debug then writeln('Env: ', allow[wide], ' files to be shown in a wide manner.');
  745.     end;
  746.     if __checkstr(swch + 'x', env, i, j) then begin
  747.       toggle(extended);
  748.       if debug then writeln(
  749.         'Env: ', dont[extended], 
  750.         'Extended information is to be shown. (' + swch + 'w may override)'
  751.       );
  752.     end;
  753.     if __checkstr(swch + 'y', env, i, j) then begin
  754.       redirect := false;
  755.       if debug then writeln('Env: Redirection linefeeds removed.');
  756.     end;
  757.  
  758.     if __checkstr(swch + 'g', env, i, j) then begin
  759.       if (
  760.         pos(upcase('p'), __up( copy(env, i, j-i) )) > 0
  761.       ) then toggle(show_pad);
  762.       if (
  763.         pos(upcase('t'), __up( copy(env, i, j-i) )) > 0
  764.       ) then toggle(greatness);
  765.       if (
  766.         pos(upcase('u'), __up( copy(env, i, j-i) )) > 0
  767.       ) then toggle(show_sum);
  768.       if (
  769.         pos(upcase('d'), __up( copy(env, i, j-i) )) > 0
  770.       ) then toggle(show_drv);
  771.       if (
  772.         pos(upcase('f'), __up( copy(env, i, j-i) )) > 0
  773.       ) then toggle(freespace);
  774.       if (
  775.         pos(upcase('n'), __up( copy(env, i, j-i) )) > 0
  776.       ) then toggle(show_num);
  777.       if debug then writeln(
  778.         'Env: ', allow[greatness], ' discsize to be calculated.'
  779.       );
  780.       if debug then writeln(
  781.         'Env: ', allow[show_sum], ' filesummation to be calculated.'
  782.       );
  783.       if debug then writeln(
  784.         'Env: ', allow[freespace], ' free discspace to be calculated.'
  785.       );
  786.       if debug then writeln(
  787.         'Env: ', allow[show_num], 
  788.         ' number of files and directories to be calculated.'
  789.       );
  790.       if debug then writeln(
  791.         'Env: ', allow[show_drv], 
  792.         ' Drive designator to be shown.'
  793.       );
  794.       if debug then writeln(
  795.         'Env: ', allow[show_pad], 
  796.         ' Drive and path designators to be shown.'
  797.       );
  798.     end;
  799.  
  800.     {▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ COMMANDLINE OVERRIDES ENVIRONMENT SETTINGS ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒}
  801.  
  802.     if __inparams(swch + 'switch', i) then begin
  803.       tmp := paramstr(i); 
  804.       writeln('Originalswitch     : -');
  805.       writeln('Switch (Env)       : ', swch);
  806.       swch := tmp[1];
  807.       writeln('Switch (Cmd)       : ', swch);
  808.     end;
  809.  
  810.     if __inparams(swch + '.', i) then begin
  811.       toggle(nopointsdir);
  812.       if debug then writeln(
  813.         'Cmd: ', show[nopointsdir], ' the . and .. directories.'
  814.       );
  815.     end;
  816.     if __inparams(swch + 'z', i) then begin
  817.       toggle(debug);
  818.       if debug then writeln('__DEBUG MODE ON__') else
  819.         writeln('__DEBUG MODE OFF__  warning: environment debugmode!');
  820.     end;
  821.     if __inparams(swch + '1', i) then begin
  822.       skind := 1;
  823.       if debug then writeln('Cmd: Eurodate set');
  824.     end;
  825.     if __inparams(swch + '2', i) then begin
  826.       skind := 2;
  827.       if debug then writeln('Cmd: American date set');
  828.     end;
  829.     if __inparams(swch + '3', i) then begin
  830.       skind := 3;
  831.       if debug then writeln('Cmd: Text date set');
  832.     end;
  833.     if __inparams(swch + '4', i) then begin
  834.       skind := 4;
  835.       if debug then writeln('Cmd: Full text date set');
  836.     end;
  837.   
  838.     if __inparams(swch + 'a', i) then begin
  839.       toggle(condition_attrs.show_arc);
  840.       if debug then writeln(
  841.         'Cmd: ', show[condition_attrs.show_arc], ' Archive atrributed files.'
  842.       );
  843.     end;
  844.     if __inparams(swch + 'b', i) then begin
  845.       toggle(condition_attrs.show_sys);
  846.       if debug then writeln(
  847.         'Cmd: ', show[condition_attrs.show_sys],
  848.         ' Boot/System attributed files.'
  849.       );
  850.     end;
  851.     if __inparams(swch + 'c', i) then begin
  852.       if debug then writeln(
  853.         'Cmd: ', show[use_colours], ' colours.'
  854.       );
  855.       toggle(use_colours);
  856.     end;
  857.     if __inparams(swch + 'd', i) then begin
  858.       toggle(dir_report);
  859.       if dir_report then findattribute := directory + only else
  860.         findattribute := anyfile;
  861.     end;
  862.  
  863.     if __inparams(swch + 'e', i) then begin
  864.       condition_attrs.sort_method := on_extension;
  865.       if debug then writeln('Cmd: Sort files on extension.');
  866.     end;
  867.   
  868.     if __inparams(swch + 'f', i) then begin
  869.       toggle(not_sum_only);
  870.       if debug then writeln(
  871.         'Cmd: ', show[not_sum_only], ' summation of bytes.'
  872.       );
  873.     end;
  874.     if __inparams(swch + 'g', i) then begin
  875.       if pos(upcase('t'), __up(paramstr(i))) > 0 then toggle(greatness);
  876.       if pos(upcase('u'), __up(paramstr(i))) > 0 then toggle(show_sum);
  877.       if pos(upcase('p'), __up(paramstr(i))) > 0 then toggle(show_pad);
  878.       if pos(upcase('d'), __up(paramstr(i))) > 0 then toggle(show_drv);
  879.       if pos(upcase('f'), __up(paramstr(i))) > 0 then toggle(freespace);
  880.       if pos(upcase('n'), __up(paramstr(i))) > 0 then toggle(show_num);
  881.       if debug then writeln(
  882.         'Cmd: ', allow[greatness], ' discsize to be calculated.'
  883.       );
  884.       if debug then writeln(
  885.         'Cmd: ', allow[show_sum], ' filesummation to be calculated.'
  886.       );
  887.       if debug then writeln(
  888.         'Cmd: ', allow[freespace], ' free discspace to be calculated.'
  889.       );
  890.       if debug then writeln(
  891.         'Cmd: ', allow[show_num], ' number of files and directories to be calculated.'
  892.       );
  893.       if debug then writeln(
  894.         'Cmd: ', allow[show_drv], ' Drive designator to be shown.'
  895.       );
  896.       if debug then writeln(
  897.         'Cmd: ', allow[show_pad], ' Drive and path designators to be shown.'
  898.       );
  899.     end;
  900.     if __inparams(swch + 'h', i) then begin
  901.       toggle(condition_attrs.show_hid);
  902.       if debug then writeln(
  903.         'Cmd: ', show[condition_attrs.show_hid], ' Hidden attributed files'
  904.       );
  905.     end;
  906.     if __inparams(swch + 'i', i) then begin
  907.       toggle(ampm);
  908.       if debug then writeln(
  909.         'Cmd: ', show[ampm], ' AmPm designator.'
  910.       );
  911.     end;
  912.     if __inparams(swch + 'j', i) then begin
  913.       if debug then writeln(
  914.         'Cmd: ', show[not condition_attrs.show_vol], ' volume-lable.'
  915.       );
  916.       toggle(condition_attrs.show_vol);
  917.     end;
  918.     if __inparams(swch + 'k', i) then begin
  919.       toggle(noscan);
  920.       if debug then writeln(
  921.         'Cmd: Kill treescan for full volume, use file.'
  922.       );
  923.     end;
  924.     if __inparams(swch + 'l', i) then begin
  925.       condition_attrs.sort_method := on_size;
  926.       if debug then writeln('Cmd: Sort files on size (fileLength)');
  927.     end;
  928.     if __inparams(swch + 'm', i) then begin
  929.       begin takemainsize := true; mainsize := __str(paramstr(i)) end;
  930.       if debug then writeln('Cmd: Take mainsize in Kbytes.');
  931.     end;
  932.     if __inparams(swch + 'n', i) then begin
  933.       toggle(condition_attrs.show_non);
  934.       if debug then writeln(
  935.         'Cmd: ', show[condition_attrs.show_r_o], ' ReadOnly attributed files'
  936.       );
  937.     end;
  938.     if __inparams(swch + 'o', i) then begin
  939.       toggle(show_date);
  940.       if debug then writeln(
  941.         'Cmd: ', show[show_date], ' date as commandline header.'
  942.       );
  943.     end;
  944.     if __inparams(swch + 'p', i) then begin
  945.       toggle(interrupted);
  946.       if debug then writeln(
  947.         'Cmd: ', allow[interrupted], ' interruption.'
  948.       );
  949.     end;
  950.     if __inparams(swch + 'q', i) then begin
  951.       toggle(sort_items);
  952.       if debug then writeln('Cmd: ', allow[sort_items], ' sorting files.');
  953.     end;
  954.     if __inparams(swch + 'r', i) then begin
  955.       toggle(condition_attrs.show_r_o);
  956.       if debug then writeln(
  957.         'Cmd: ', show[condition_attrs.show_r_o], ' ReadOnly attributed files.'
  958.       );
  959.     end;
  960.     if __inparams(swch + 's', i) then begin
  961.       toggle(globaltree);
  962.       if debug then writeln(
  963.         'Cmd: ', dont[globaltree], ' scan subtree of current directory.'
  964.       );
  965.     end;
  966.     if __inparams(swch + 't', i) then begin
  967.       condition_attrs.sort_method := on_datetime;
  968.       if debug then writeln('Cmd: Sort files on time and date.');
  969.     end;
  970.     if __inparams(swch + 'u', i) then begin
  971.       manipulate := __str(paramstr(i));
  972.       if debug then writeln('Cmd: The case is ', mani[manipulate], '.');
  973.       if manipulate = 2 then manipulate := _to_upcase_str else
  974.         if manipulate = 1 then manipulate := _to_lowcase_str else
  975.           manipulate := 0;
  976.     end;
  977.     if __inparams(swch + 'v', i) then begin
  978.       condition_attrs.sort_method := on_name;
  979.       if debug then writeln('Cmd: Sort files verbosely (on name).');
  980.     end;
  981.     if __inparams(swch + 'w', i) then begin
  982.       toggle(wide);
  983.       if debug then writeln(
  984.         'Cmd: ', allow[wide], ' files to be shown in a wide manner.'
  985.       );
  986.     end;
  987.     if __inparams(swch + 'x', i) then begin
  988.       toggle(extended);
  989.       if debug then writeln(
  990.         'Cmd: ', dont[extended], 'Extended information to be shown. (' + swch + 'w may override)'
  991.       );
  992.     end;
  993.     if __inparams(swch + 'y', i) then begin
  994.       redirect := false;
  995.       if debug then writeln('Cmd: Redirection linefeeds removed.');
  996.     end;
  997.   end;
  998.  
  999.  
  1000.  
  1001.   function first_is_param(s: string): boolean;
  1002.   var swch : char;
  1003.   begin
  1004.     swch := originalswitch;
  1005.     { 
  1006.       if we get here, the swicthchar may have been altered,
  1007.       so we match against the original switch, the logic of which is,
  1008.       that in order to alter the switchchar, the option that enables
  1009.       this function is switched itself, with a standard switchchar, after
  1010.       which usage, the testing will not work anymore
  1011.     }
  1012.     first_is_param := (
  1013.       { debugging or help }
  1014.       __comp(s, swch + '?') or __comp(s, swch + 'switch') or (
  1015.       { normal options }
  1016.         (upcase(s[2]) in ['1'..'4', 'A'..'Z']) and (s[1] = swch) and
  1017.         (length(__nw(s))=2)
  1018.       ) or (
  1019.         __comp(s, swch + '.')
  1020.       )
  1021.     )
  1022.   end;
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.   function __retrievecolour(re: searchrec): byte;
  1030.   var t : byte;
  1031.   begin
  1032.     __retrievecolour := normalcolour;
  1033.     if use_colours then begin
  1034.       if __attrfilter(
  1035.         re.attr, directory + only
  1036.       ) then __retrievecolour := attr_colours[0].colour else
  1037.         if __attrfilter(
  1038.           re.attr, volumeid + only
  1039.         ) then __retrievecolour := attr_colours[1].colour else if not(
  1040.           __nonascii(re.name) or (__extractext(re.name) = '')
  1041.         ) then begin
  1042.           for t := 4 to max_colours_env do if __comp(
  1043.             __extractext(re.name), attr_colours[t].ext
  1044.           ) then __retrievecolour := attr_colours[t].colour;
  1045.         end;
  1046.     end;
  1047.   end;
  1048.  
  1049.  
  1050.   procedure checkintr(line, j: word);
  1051.   begin
  1052.     if redirectpressed then begin
  1053.       textcolour(yellow);
  1054.       if use_colours then textbackground(blue);
  1055.       write('(PRESS)');
  1056.       readkey; readkey; 
  1057.       write(__rep(7, #8));
  1058.       textcolour(normalcolour);
  1059.       if use_colours then textbackground(black);
  1060.       write(__rep(7, ' '), __rep(7, #8));
  1061.     end else if not(redirect) and interrupted and (
  1062.       (j = 0) or (j = cols-1)
  1063.     ) and (
  1064.       (
  1065.         (line mod (_currows-1) = 0) and
  1066.         not globaltree
  1067.       ) or (
  1068.         (
  1069.           (totlin >= _currows-1)
  1070.         ) and globaltree and (totlin > 0)
  1071.       )
  1072.     ) then begin
  1073.       textcolour(yellow); totlin := 0;
  1074.       if use_colours then textbackground(blue);
  1075.       write('(PRESS)');
  1076.       readkey;
  1077.       write(__rep(7, #8));
  1078.       textcolour(normalcolour);
  1079.       if use_colours then textbackground(black);
  1080.       write(__rep(7, ' '), __rep(7, #8));
  1081.     end;
  1082.   end;
  1083.  
  1084.  
  1085.  
  1086.   procedure widedispline(i: word);
  1087.   var k : word;
  1088.   begin
  1089.     j := 0;
  1090.     while (j < cols) do begin
  1091.       k := i + (j * coll);
  1092.       textcolour(__retrievecolour(filarray^[k]^));
  1093.       if not (
  1094.         __nonascii(filarray^[k]^.name)
  1095.       ) then begin
  1096.         if (
  1097.           ((filarray^[k]^.attr and directory) > 0)
  1098.         ) and (
  1099.           __nw(filarray^[k]^.name) <> '' 
  1100.         ) then write(
  1101.           __juststr(
  1102.             '[' + filarray^[k]^.name + ']',
  1103.             ' ', 16, _left_just_str
  1104.           )
  1105.         ) else if (
  1106.           ((filarray^[k]^.attr and volumeid) > 0) 
  1107.         ) and (
  1108.           __nw(filarray^[k]^.name) <> '' 
  1109.         ) then write(
  1110.           __juststr(
  1111.             '{' + __rempoint(filarray^[k]^.name) + '}',
  1112.             ' ', 16, _left_just_str
  1113.           )
  1114.         ) else if true or (__nw(filarray^[k]^.name) <> '') then write(
  1115.           __juststr(filarray^[k]^.name, ' ', 16, _left_just_str)
  1116.         );
  1117.       end else write(' ' : 16);
  1118.       inc(j); checkintr(i, j);
  1119.       textcolour(normalcolour);
  1120.     end;
  1121.     if redirect then writeln; 
  1122.     {
  1123.       if redirect then linefeed after line:
  1124.       con does it automatically, file does not 
  1125.     }
  1126.   end;
  1127.  
  1128.  
  1129.  
  1130.  
  1131.   procedure processdirectory(search: string);
  1132.   var colnr : word;
  1133.   begin
  1134.     if debug then write('Filitems:ColumnLen : '); 
  1135.     if debug then write(filitems, ':'); colnr := _curcolumns div 16;
  1136.     i := 0; coll := (filitems div colnr);
  1137.     if filitems mod colnr <> 0 then inc(coll);
  1138.     if debug then writeln(coll);
  1139.  
  1140.     if wide then begin
  1141.       if not_sum_only then for i := 1 to coll do begin
  1142.         widedispline(i); inc(totlin);
  1143.       end;
  1144.     end else begin
  1145.       if not_sum_only then for i := 1 to filitems do begin
  1146.         inc(totlin);
  1147.         st := __searchrec(
  1148.           {srec} filarray^[i]^,
  1149.           {numb} i,
  1150.           {kind} skind,
  1151.           {main} mainsize, 
  1152.           {take} false,
  1153.           {extn} extended,  { size in K, number }
  1154.           {ampm} ampm,
  1155.           {attr} true,
  1156.           {wide} wide
  1157.         );
  1158.         if extended then j := 4 else j := 1;
  1159.         write(__part(st, 1, j));
  1160.         textcolour(__retrievecolour(filarray^[i]^));
  1161.         write(__part(st, j, j+13));
  1162.         textcolour(normalcolour);
  1163.         write(__part(st, j+14, length(st)));
  1164.         checkintr(i, 0);
  1165.         writeln;
  1166.       end;
  1167.       writeln;
  1168.     end;
  1169.     totgen := totgen + tot;
  1170.   end;
  1171.  
  1172.  
  1173.  
  1174.   procedure errorhandler(number, adres:integer);
  1175.   begin
  1176.     chdir(olddospath); exitproc := oldexitproc;
  1177.     textbackground(0);
  1178.     if debug then begin
  1179.       writeln('Files: ', filitems, '  Mem: ', maxavail);
  1180.     end;
  1181.     writeln('*user break*'); halt
  1182.   end; { errorhandler }
  1183.  
  1184.  
  1185.  
  1186.   {$F+}
  1187.   function dir_condition(var srec): boolean;
  1188.   begin
  1189.     with std_condition_attrs do dir_condition := (
  1190.       ((searchrec(srec).attr and volumeid ) > 0) or
  1191.       ((searchrec(srec).attr and directory) > 0)
  1192.     ) and not (
  1193.       nopointsdir and (
  1194.         (searchrec(srec).name = '.') or
  1195.         (searchrec(srec).name = '..')
  1196.       )
  1197.     );
  1198.   end; { dir_conditio }
  1199.  
  1200.  
  1201.  
  1202.   function new_condition(var srec): boolean;
  1203.   begin
  1204.     new_condition := (
  1205.       std_condition(searchrec(srec)) and not(
  1206.         (searchrec(srec).name = '.') or
  1207.         (searchrec(srec).name = '..')
  1208.       )
  1209.     );
  1210.   end; { new_condition }
  1211.  
  1212.  
  1213.  
  1214.   procedure parse_colour_string(s: string);
  1215.   var
  1216.     t, tt, mx,
  1217.     i, k, col :                 word;
  1218.     tmp       : attr_colours_type_ar;
  1219.  
  1220.   begin
  1221.     if debug then begin
  1222.       writeln('Standard Colours: ');
  1223.       for i := 1 to max_colours do begin
  1224.         textcolour(attr_colours[i].colour);
  1225.         write(attr_colours[i].ext + ' ');
  1226.       end;
  1227.       textcolour(normalcolour); writeln;
  1228.     end;
  1229.     if s <> '' then begin
  1230.       {
  1231.         de idee:
  1232.         we lopen met `t' door de range
  1233.         `tt' is het vorige begin van t, zodat we de sub-range kennen, om
  1234.         later in een batch de kleur aan toe te kennen.
  1235.         `i' en `j' worden de lopende variables in de te parsen string `s'
  1236.       }
  1237.       t := 0; j := 1; mx := length(s)+1;
  1238.       if debug then begin
  1239.         writeln(s, '  ', mx);
  1240.         writeln('123456789-123456789-123456789-123456789-123456789-123');
  1241.       end;
  1242.       { dir:12 vol: 13 arc,arj,lzh,zip,zoo:14 txt,doc:15 }
  1243.  
  1244.       while (t < max_colours) and (j < mx) do begin
  1245.         tt := t;
  1246.         while (s[j] <> ':') and (j < mx) do begin
  1247.           i := j; { i op j zetten, en j laten lopen }
  1248.           while not(s[j] in [',', ':']) and (j < mx) do inc(j);
  1249.           { we hebben woord t }
  1250.           tmp[t].ext := __nw(__part(s, i, j-1));
  1251.           if debug then writeln(
  1252.             't=', t:2, ' tt=', tt:2, '  ', 'i=', i:2, 
  1253.             ' "', __nw(__part(s, i, j-1)), '" ', '  j=', j:2
  1254.           );
  1255.           inc(t); if s[j] <> ':' then inc(j);
  1256.         end;
  1257.         { nu colon }
  1258.         inc(j); i := j; while (s[j] <> ' ') and (j < mx) do inc(j);
  1259.         { kleurcode }
  1260.         col := __str(__nw(__part(s, i , j)));
  1261.         if debug then begin
  1262.           textcolour(col);
  1263.           writeln(tmp[t-1].ext);
  1264.           textcolour(normalcolour);
  1265.         end;
  1266.         for k := tt to t do tmp[k].colour := col;
  1267.         inc(j);
  1268.       end;
  1269.       attr_colours := tmp;
  1270.     end; { s > '' }
  1271.     max_colours_env := t;
  1272.     if debug then writeln('New max_colours    : ', t);
  1273.     normalcolour := tmp[3].colour;
  1274.   end;
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281. {main}begin
  1282.   redirect := not __isconfil(__handlfil(output)); findattribute := anyfile;
  1283.   swch := '-'; originalswitch := swch; max_colours_env := max_colours;
  1284.  
  1285.   { init }
  1286.   oldexitproc := exitproc; exitproc := @errorhandler;
  1287.   cols := _curcolumns div 16; mainsize := 1024; 
  1288.   set_std_condition_attrs(condition_attrs); manipulate := 0;
  1289.  
  1290.   env := getenv('WDIR');
  1291.   colour_string := getenv('WCOLOURS');
  1292.   if __comp(colour_string, '') then colour_string := '';
  1293.   treeinfosource := getenv('WTREEINFO');
  1294.  
  1295.   skind := 3; totgen := 0;
  1296.   getparams;
  1297.  
  1298.   if __inparams(swch + '?', i) then help;
  1299.   if not greatness then packsize := 35;
  1300.   if colour_string <> '' then parse_colour_string(colour_string);
  1301.   if show_date then begin
  1302.     if not debug then gotoxy(1, wherey-1); clreol;
  1303.     textcolour(attr_colours[2].colour);
  1304.     write(__todaystr(false), '  ', __curdate); 
  1305.     textcolour(normalcolour); writeln;
  1306.   end;
  1307.  
  1308.   { search expansion }
  1309.   searchpath := paramstr(1);
  1310.  
  1311.   if (__lastchr(searchpath) = '.') and not (
  1312.     searchpath[length(searchpath)-1] in ['.', swch]
  1313.   ) then comexebatcmdfilter := true;
  1314.   if comexebatcmdfilter then writeln('Executable filter:');
  1315.   searchpath := __normfil(searchpath);
  1316.  
  1317.   if first_is_param(paramstr(1)) or (paramcount = 0) then begin
  1318.     searchbasis := __normfil(__backapp(__curdir));
  1319.     searchpattern := '*.*';
  1320.   end else if (             { searchpath is specified }
  1321.     (pos('*', searchpath) = 0) and (pos('?', searchpath) = 0)
  1322.   ) then begin { no wildcard, so entire director(y/ies) }
  1323.     searchbasis := __normfil(__backapp(searchpath));
  1324.     searchpattern := '*.*';
  1325.   end else begin       { wildcards/pattern, so selection of director(y/ies) }
  1326.     searchbasis := __normfil(__backapp(__extractpath(searchpath)));
  1327.     searchpattern := __extractnamext(searchpath);
  1328.   end;
  1329.  
  1330.  
  1331.   if (swch <> '/') and (paramstr(1) = '/?') then writeln(
  1332.     'Help: ', __progname, ' ', swch, 
  1333.     '?   (now searching ? in root of ' + upcase(searchbasis[1]) + ':)'
  1334.   );
  1335.  
  1336.   { dir expansion }
  1337.   set_std_condition_attrs(condition_attrs);
  1338.  
  1339.   {
  1340.     expressly after search, so in case path(1) = param(?), 
  1341.     the path is evaluated first, and / trans to \, (therefore no param)
  1342.   }
  1343.  
  1344.   if not __existpath(__normfil(searchbasis)) then begin
  1345.     write('Path does not exist: "', searchpath, '"');
  1346.     exitproc := oldexitproc; halt(5);
  1347.   end else if (
  1348.     not(__findfil(__normfil(searchbasis+searchpattern), tmp)) and 
  1349.     not(globaltree) and
  1350.     not(__existfil(__normfil(searchbasis+searchpattern)))
  1351.   ) then begin
  1352.     write('File does not exist: "', searchbasis, '"'); exitproc := oldexitproc; halt(2);
  1353.   end;
  1354.  
  1355.   olddospath := __curdir;
  1356.   chdir(__backrem(searchbasis));
  1357.  
  1358.   __drvparm(upcase(searchbasis[1]));
  1359.  
  1360.  
  1361.   if sort_items then sort_ptr := @std_sort else sort_ptr := nil;
  1362.   if dir_report then attr_ptr := @dir_condition else if
  1363.     nopointsdir then attr_ptr := @new_condition else
  1364.       attr_ptr := @std_condition;
  1365.  
  1366.   if debug then begin
  1367.     writeln('Environment        : "', env, '"');
  1368.     writeln('                   : "', colour_string, '"');
  1369.     write  ('Commandline        : "');
  1370.     for i := 1 to paramcount do write(paramstr(i), ' ');
  1371.     writeln('"');
  1372.     writeln('Switch (override)  : "', swch, '"');
  1373.     writeln('Sort pointer       : "', __ptr2str(sort_ptr), '"');
  1374.     writeln('Manipulate case    : "', manipulate, '"');
  1375.     writeln('Global tree        : "', globaltree, '"');
  1376.     writeln('Searchpath         : "', searchpath, '"');
  1377.     writeln('Searchbasis        : "', searchbasis, '"');
  1378.     writeln('Searchpattern      : "', searchpattern, '"');
  1379.   end;
  1380.  
  1381.  
  1382.   if globaltree then totlin := 2 else totlin := 1;
  1383.   if globaltree then begin { do it }
  1384.     write('Reading subtree...');
  1385.     if treeinfosource <> '' then
  1386.       treeinfodrivechar := upcase(treeinfosource[1]) else
  1387.       treeinfodrivechar := upcase(searchbasis[1]);
  1388.     drivechar := upcase(searchbasis[1]);
  1389.  
  1390.     if debug then writeln(treeinfodrivechar + treeinfofile + drivechar);
  1391.     if noscan and (length(searchbasis) < 4) {root} and __existfil(
  1392.       treeinfodrivechar + treeinfofile + drivechar
  1393.     ) then begin
  1394.       load_tree(treeinfodrivechar + treeinfofile + drivechar);
  1395.       writeln;
  1396.     end else begin
  1397.       trace_tree;
  1398.       if length(searchbasis) < 4 then save_tree(
  1399.         treeinfodrivechar + treeinfofile + drivechar
  1400.       );
  1401.     end;
  1402.  
  1403.     for nod := 0 to nodenumber-1 do begin
  1404.       new_filarray(filarray);
  1405.       filitems := 0; tot := 0;
  1406.       __dirutl(
  1407.         comexebatcmdfilter,
  1408.         __normfil(__backapp(searchbasis) + trace_path(nod)) + searchpattern,
  1409.         filarray,
  1410.         findattribute, manipulate, error, dirs, volum,
  1411.         attr_ptr,
  1412.         sort_ptr,
  1413.         tot
  1414.       );
  1415.       writeln(
  1416.         __cvtstr(
  1417.           __xlatestr(
  1418.             __normfil(
  1419.               __backapp(searchbasis + trace_path(nod))
  1420.             ) + searchpattern, '\', _dirslash
  1421.           ), manipulate
  1422.         ) + '  (' + __num(filitems) + ' : ' +
  1423.         __pntstr(tot) + ')'
  1424.       );
  1425.       processdirectory(
  1426.         __backrem(__normfil(__backapp(searchbasis) + trace_path(nod))) + searchpattern
  1427.       );
  1428.       dispose_filarray(filarray);
  1429.       if wherex > 1 then writeln;
  1430.       writeln;
  1431.       if wide then inc(totlin, 2) else inc(totlin, 3);
  1432.     end
  1433.   end else begin
  1434.     new_filarray(filarray);
  1435.     filitems := 0; tot := 0;
  1436.     __dirutl(
  1437.       comexebatcmdfilter,
  1438.       searchbasis + searchpattern, filarray,
  1439.       findattribute, manipulate, error, dirs, volum,
  1440.       attr_ptr,
  1441.       sort_ptr,
  1442.       tot
  1443.     );
  1444.     processdirectory(__normfil(searchbasis) + searchpattern);
  1445.     if wherex > 1 then writeln;
  1446.  
  1447.     if show_pad then show_drv := true;
  1448.     if show_drv then begin
  1449.       if show_pad then st := __slashfil(
  1450.         __packfil(__backrem(__curdir), packsize)
  1451.       ) else st := upcase(searchbasis[1]) + ':';
  1452.       if freespace or greatness then st := st + ' ';
  1453.     end else st := '';
  1454.  
  1455.     if greatness then begin
  1456.       st := st + 'T ' + __pntstr(_dosdiscsize) + ' ';
  1457.     end;
  1458.     if freespace then st := st + ' F ' + __pntstr(_dosdiscfree) + ' '; 
  1459.  
  1460.     tmp := '';
  1461.     if show_sum then tmp := 'U ' + __pntstr(tot) + ' b ';
  1462.     if show_num then tmp := tmp + '[' + 
  1463.       __pntstr(dirs) + '](' + __pntstr(filitems-dirs) + ')';
  1464.  
  1465.     if freespace or greatness then st := st + 'b';
  1466.     if freespace or greatness or show_sum then begin
  1467.       textcolour(attr_colours[2].colour);
  1468.       write(
  1469.         tmp, ' ' : (_curcolumns - length(st)-length(tmp)-1), st
  1470.       );
  1471.       textcolour(normalcolour); writeln;
  1472.     end;
  1473.     dispose_filarray(filarray);
  1474.   end;
  1475.  
  1476.   if globaltree then begin
  1477.     textcolour(attr_colours[2].colour);
  1478.     write(__pntstr(totgen));
  1479.     textcolour(normalcolour); writeln;
  1480.   end;
  1481.   chdir(olddospath);
  1482.   exitproc := oldexitproc;
  1483. {happy}end.
  1484.  
  1485.