home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume12 / cake / part04 / Aux / gsrc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-14  |  807 b   |  54 lines

  1. /*
  2. **    Track down ultimate source files.
  3. */
  4.  
  5. #include    <stdio.h>
  6. #include    <sys/types.h>
  7. #include    <sys/stat.h>
  8. #include    "std.h"
  9.  
  10. main(argc, argv)
  11. int    argc;
  12. char    **argv;
  13. {
  14.     char        buf[80];
  15.     struct    stat    statbuf;
  16.     reg    int    i, j;
  17.     reg    int    lastsuf, firstfile;
  18.     reg    bool    found;
  19.  
  20.     lastsuf = 0;
  21.     firstfile = argc;
  22.     for (i = 1; i < argc; i++)
  23.     {
  24.         if (argv[i][0] == '.')
  25.             lastsuf = i;
  26.         or (firstfile == argc)
  27.             firstfile = i;
  28.     }
  29.  
  30.     if (lastsuf > firstfile)
  31.     {
  32.         fprintf(stderr, "gsrc: mixed suffixes and filenames\n");
  33.         exit(1);
  34.     }
  35.  
  36.     for (i = firstfile; i < argc; i++)
  37.     {
  38.         found = FALSE;
  39.         for (j = lastsuf; j > 0; j--)
  40.         {
  41.             sprintf(buf, "%s%s", argv[i], argv[j]);
  42.             if (stat(buf, &statbuf) == 0)
  43.             {
  44.                 if (! found)
  45.                     found = TRUE;
  46.                 else
  47.                     printf("%s%s\n", argv[i], argv[j]);
  48.             }
  49.         }
  50.     }
  51.  
  52.     exit(0);
  53. }
  54.