home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 2.ddi / CLASSEXM.ZIP / TESTDIR.CPP < prev   
Encoding:
C/C++ Source or Header  |  1991-02-13  |  3.0 KB  |  125 lines

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