home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 8.img / CLASSEXM.ZIP / TESTDIR.CPP < prev   
Encoding:
C/C++ Source or Header  |  1990-05-04  |  3.2 KB  |  134 lines

  1. //
  2. // This file contains proprietary information of Borland International.
  3. // Copying or reproduction without prior written approval is prohibited.
  4. //
  5. // Copyright (c) 1990
  6. // Borland International
  7. // 1800 Scotts Valley Dr.
  8. // Scotts Valley, CA 95066
  9. // (408) 438-8400
  10. //
  11.  
  12. // Contents ----------------------------------------------------------------
  13. //
  14. //     main
  15. //
  16. // Description
  17. //
  18. //     Directory listing program.  Lists directories in the given sorting
  19. //     order.
  20. //
  21. // End ---------------------------------------------------------------------
  22.  
  23. // Interface Dependencies ---------------------------------------------------
  24.  
  25. // None
  26.  
  27. // End Interface Dependencies ------------------------------------------------
  28.  
  29. // Implementation Dependencies ----------------------------------------------
  30.  
  31. #ifndef __STDLIB_H
  32. #include <stdlib.h>
  33. #define __STDLIB_H
  34. #endif
  35.  
  36. #ifndef __IOSTREAM_H
  37. #include <iostream.h>
  38. #define __IOSTREAM_H
  39. #endif
  40.  
  41. #ifndef __DIRECTRY_H
  42. #include "directry.h"
  43. #endif
  44.  
  45. // End Implementation Dependencies -------------------------------------------
  46.  
  47.  
  48. // Function //
  49.  
  50. int    main( int argc, char *argv[] )
  51.  
  52. // Summary -----------------------------------------------------------------
  53. //
  54. //     directry [options] template
  55. //
  56. //     Displays a sorted listing of the given pathnames.  The template
  57. //     may contain wildcard characters.
  58. //
  59. //     options:  One of the following
  60. //
  61. //     -sn        Sort by name
  62. //
  63. //     -sd        Sort by date
  64. //
  65. //     -ss        Sort by size
  66. //
  67. // Parameters
  68. //
  69. //     argc
  70. //
  71. //     The number of arguments passed on the command line.  There must
  72. //     be at least 1 argument other than the command name.
  73. //
  74. //     argv
  75. //
  76. //     A vector of character strings which are the arguments to the
  77. //     command line.
  78. //
  79. // End ---------------------------------------------------------------------
  80. {
  81.     if ( argc < 2 || argc > 3 )
  82.     {
  83.         cerr << "Usage:  directry [options] template\n";
  84.         exit(1);
  85.     }
  86.  
  87.     sortOrder sorting;              // Defines the sorting order for the
  88.                                     // pathnames.
  89.  
  90.     int path;                       // Defines the argument at which the
  91.                                     // pathname occurs.
  92.  
  93.     if ( argc != 3 )
  94.     {
  95.     sorting = Directory::byName;
  96.     path = 1;
  97.     }
  98.     else // the optional sort argument was specified.
  99.     {
  100.         String sortArg( argv[1] );
  101.         String sortByName( "-sn" );
  102.         String sortByDate( "-sd" );
  103.         String sortBySize( "-ss" );
  104.  
  105.         path = 2;
  106.  
  107.         if ( sortArg == sortByName )
  108.         {
  109.         sorting = Directory::byName;
  110.         }
  111.         else if ( sortArg == sortByDate )
  112.         {
  113.         sorting = Directory::byDate;
  114.         }
  115.         else if ( sortArg == sortBySize )
  116.         {
  117.         sorting = Directory::bySize;
  118.         }
  119.     }
  120.  
  121. // Body Comment
  122. //
  123. //     At this point, we will have established our sorting order.
  124. //     We now construct a directory list of the given sort order
  125. //     and display that list.
  126. //
  127. // End
  128.  
  129.     Directory sortedDirectory( argv[path], sorting );
  130.     sortedDirectory.printContentsOn( cout );
  131. }
  132. // End Function main //
  133.  
  134.