home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / language / perl / Source / C / Glob < prev    next >
Encoding:
Text File  |  1990-11-11  |  779 b   |  52 lines

  1. /* Globbing for the Archimedes.
  2.  */
  3.  
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include "utils.h"
  7.  
  8. #define OPTIONS "?ns"
  9.  
  10. #define USAGE \
  11. "Usage: Glob [options] pattern...\n" \
  12. "\n" \
  13. "Options:\n" \
  14. "    -n     Separate values with newline instead of null\n" \
  15. "    -s     Separate values with a space instead of null\n" \
  16. "\n"
  17.  
  18. int main(int argc, char *argv[])
  19. {
  20.     char *name;
  21.     int opt;
  22.     char sep = 0;
  23.  
  24.     while ((opt = getopt(argc, argv, OPTIONS)) != EOF)
  25.     {
  26.         switch (opt)
  27.         {
  28.         case 'n':
  29.             sep = '\n';
  30.             break;
  31.         case 's':
  32.             sep = ' ';
  33.             break;
  34.         default:
  35.             fputs(USAGE,stderr);
  36.             return (opt != '?');
  37.         }
  38.     }
  39.  
  40.  
  41.     for (; optind < argc; ++optind)
  42.     {
  43.         for (name = dirscan(argv[optind]); name; name = dirscan(0))
  44.         {
  45.             fputs(name, stdout);
  46.             putchar(sep);
  47.         }
  48.     }
  49.  
  50.     return 0;
  51. }
  52.