home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / PBL30SAM.ZIP / DLSTEST1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-02  |  2.1 KB  |  103 lines

  1. #include "dlist.h"
  2. #include <iostream.h>
  3. #include <string.h>
  4. #include <dir.h>
  5. #include <alloc.h>
  6. #include <conio.h>
  7.  
  8. struct TFileInfo
  9. {
  10.     char name[13];
  11.     long date;
  12.     long size;
  13.  
  14.     TFileInfo(char *aName, long aDate, long aSize):
  15.         date(aDate), size(aSize) { strcpy(name, aName); }
  16. };
  17.  
  18. static void display(TFileInfo *item);
  19.  
  20.     int
  21. main( int argc, char *argv[] )
  22. {
  23.     zDoubleList dirList(True);
  24.     struct ffblk f;
  25.  
  26.     if( !--argc ){
  27.         cerr << "Usage: " << *argv << " filespec" << endl;
  28.         return 1;
  29.     }
  30.  
  31.     cout << "InitHeap: " << coreleft() << endl;
  32.  
  33.     // build the list
  34.     cout << "Building the file list...";
  35.     int done = findfirst(argv[1], &f, 0);
  36.     while( !done ){
  37.         if( '.' != f.ff_name[0] ){
  38.             dirList.link(new TFileInfo(f.ff_name, f.ff_fdate, f.ff_fsize));
  39.             if( dirList.error() ){
  40.                 cerr << "\nOut of memory" << endl;
  41.                 return 1;
  42.             }
  43.         }
  44.         done = findnext(&f);
  45.     }
  46.  
  47.     cout << "There are " << dirList.size()
  48.          << " files in " << argv[1] << endl;
  49.  
  50.     if( dirList.size() ){
  51.         zListCursor c(dirList, True);
  52.         cout << "Use the arrow keys to display.\n" << endl;
  53.         display((TFileInfo *)c.get());
  54.         do{
  55.             int ch;
  56.  
  57.             while( 0 == (ch = getch()) )
  58.                 ;
  59.  
  60.             switch( ch ){
  61.                 case 0x1b: goto Quit;
  62.  
  63.                 case 0x4b:
  64.                     c.begin();
  65.                     display((TFileInfo *)c.get());
  66.                 break;
  67.  
  68.                 case 0x4d:
  69.                     c.end();
  70.                     display((TFileInfo *)c.get());
  71.                 break;
  72.  
  73.                 case 0x50:
  74.                     if( c.next() ) display((TFileInfo *)c.get());
  75.                     else cerr << ">>At end of list." << endl;
  76.                 break;
  77.  
  78.                 case 0x48:
  79.                     if( c.prev() ) display((TFileInfo *)c.get());
  80.                     else cerr << ">>At start of list." << endl;
  81.                 break;
  82.  
  83.                 default:
  84.                     cerr << ">>Up/Down/Left/Right/Escape are recognized." << endl;
  85.             }
  86.         }while(1);
  87.     }
  88.  
  89. Quit:
  90.     dirList.~zDoubleList();
  91.     cout << "TermHeap: " << coreleft();
  92.     return 0;
  93. }
  94.  
  95.  
  96. void display(TFileInfo *item)
  97. {
  98.     if( 0 == item ) cerr << "No item" << endl;
  99.     else{
  100.         cout << "'" << strlwr(item->name) << "' "
  101.              << item->size << " bytes" << endl;
  102.     }
  103. }