home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 1.ddi / OOPWLD.ZIP / DIRECT / TREETEST.CPP < prev   
Encoding:
C/C++ Source or Header  |  1990-06-11  |  1.3 KB  |  37 lines

  1. // TREETEST.CPP : test of directory tree (sorted directory)
  2. #include "dirtree.hpp"
  3. #include <stdlib.h>
  4.  
  5. main(int argc, char * argv[]) {
  6.   char * filespec = (argc > 1 ? argv[1] : "*.*");
  7.   ffblk file_info;
  8.   int done = findfirst(filespec, &file_info, 0x37);
  9.   if(done) exit(0);  // no files to find!
  10.   dirtree tree(new dirfile3(&file_info));
  11.   int count = 0;
  12.   while(!done) {
  13.     tree.add(new dirfile3(&file_info)); // sloppy, but OK
  14.     count++;
  15.     done = findnext(&file_info);
  16.   }
  17.   dlist dl(count); // make a list big enough to hold all elements
  18.   tree.distribute(dl); // place the elements sequentially in dl
  19.   puts("\n---------- Horizontal listing ------------");
  20.   for(int x = 0; x < count; x++)
  21.     dl[x]->print2();
  22.   puts("\n---------- Vertical Columns --------------");
  23.   const rows = count/4 + 1;
  24.   // an array of 4 dlists:
  25.   dlist column[] = { rows, rows, rows, rows };
  26.   int ndx = -1, i, j;
  27.   for(j = 0; j < 4; j++)
  28.     for(i = 0; i < rows; i++) {
  29.       if(++ndx >= count) break;
  30.       column[j].add(dl[ndx]); // distribute among the four columns
  31.     }
  32.   dirfile3::reset_printcount();  // call a static member function
  33.   for(i = 0; i < rows; i++)
  34.     for(j = 0; j < 4; j++)
  35.       column[j][i]->print2(); // print the columns out vertically
  36. }
  37.