home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / GNU / PL4019AS.ZIP / PERLGLOB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-26  |  1.4 KB  |  69 lines

  1. /* Glob support for MS-DOS PERL
  2.  * 
  3.  * Copyright 1992, Stuart G. Phillips
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  * To compile without a makefile use the following command:
  9.  *
  10.  *        bcc -ms -eperlglob perlglob.c
  11.  *
  12.  * and stand back !.
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <dir.h>
  18.  
  19. /* The following define controls how many files we will process.
  20.  * 1024 *should* be big enough for most DOS systems.
  21.  */
  22.  
  23. #define NFNAMES    1024
  24.  
  25.  
  26. #define TRUE    1
  27. #define FALSE    0
  28.  
  29. char fnames[NFNAMES][14];
  30. int sort_function(const void *a, const void *b);
  31.  
  32. void main(int argc, char *argv[])
  33. {
  34.     struct ffblk fb;
  35.     char *env, *s;
  36.     int no_more = FALSE, i, uc = FALSE, nf = 0;
  37.  
  38.     if (argc < 2)
  39.         exit(1);
  40.  
  41.     if ((env = getenv("PERLGLOB")) != NULL) 
  42.         if (env[0] == 'U' || env[0] == 'u')
  43.             uc = TRUE;
  44.  
  45.     for (i = 1; i <argc; i++) {
  46.         no_more = findfirst(argv[i],&fb,0);
  47.         while (!no_more && nf < NFNAMES) {
  48.             if (!uc)
  49.                 strlwr(fb.ff_name);
  50.             strcpy(fnames[nf++],fb.ff_name);
  51.             no_more = findnext(&fb);
  52.         }
  53.     }
  54.  
  55. done_search:
  56.  
  57.     qsort(fnames, nf, 14, sort_function);
  58.  
  59.     for (i=0; i < nf; i++)
  60.         printf("%s\n",fnames[i]);
  61.  
  62.     exit(0);
  63. }
  64.  
  65. int sort_function(const void *a, const void *b)
  66. {
  67.     return(strcmp((char *)a,(char *)b));
  68. }
  69.