home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ECO30603.ZIP / ECO30603.LZH / ECOLIBBS / W.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1993-02-17  |  44.8 KB  |  1,466 lines

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