home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / libgplus.5 / libgplus / etc / lf / option.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-17  |  1.4 KB  |  66 lines

  1. /* Process directory listing program options. */
  2. #include <stdio.h>
  3. #include <std.h>
  4. #include <GetOpt.h>
  5. #include "option.h"
  6.  
  7. /* Initialize the program options. */
  8.  
  9. unsigned  Option_Handler::option_word;
  10. char    * Option_Handler::program_name;
  11.  
  12. Option_Handler::Option_Handler (void)
  13. {     
  14.   option_word = 0;
  15. }
  16.  
  17. /* Prints program usage to standard error stream, then exits. */
  18.  
  19. void 
  20. Option_Handler::usage (void)
  21.   fprintf (stderr, "usage: %s [-ahl] [directory]\n", program_name);
  22.   exit (1);
  23. }
  24.  
  25. /* Sets the program options. */
  26.  
  27. void 
  28. Option_Handler::operator () (int argc, char *argv[])
  29. {
  30.   GetOpt getopt (argc, argv, "ahl");
  31.   int option_char;
  32.  
  33.   program_name = argv[0];
  34.  
  35.   while ((option_char = getopt ()) != EOF)
  36.     switch (option_char)
  37.       {
  38.       case 'a':                 /* Print out hidden files (those starting with '.'). */
  39.         option_word |= HIDDEN;
  40.         break;
  41.       case 'l':
  42.         option_word |= LINK;
  43.         break;
  44.       case 'h': /* Print help message and exit. */
  45.       default:
  46.         usage ();
  47.       }
  48.  
  49.   /* Change the working directory if default is not ".". This saves
  50.      time during the directory entry decoding phase. */
  51.  
  52.   if (argv[getopt.optind])
  53.     chdir (argv[getopt.optind]);
  54. }
  55.  
  56. #ifndef __OPTIMIZE__
  57. /* TRUE if OPTION enable, else FALSE. */
  58.  
  59. int
  60. Option_Handler::operator[] (option_type option) 
  61.   return option_word & option;
  62. }
  63. #endif // __OPTIMIZE__
  64.