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

  1. /*
  2. **    Find out which arg files are later than a reference file.
  3. */
  4.  
  5. static    char
  6. rcs_id[] = "$Header$";
  7.  
  8. #include    <stdio.h>
  9. #include    <sys/types.h>
  10. #include    <sys/stat.h>
  11. #include    "std.h"
  12.  
  13. typedef    struct    stat    Stat;
  14.  
  15. char    scratchbuf[128];
  16.  
  17. main(argc, argv)
  18. int    argc;
  19. char    **argv;
  20. {
  21.     Stat        statbuf;
  22.     reg    time_t    reftime;
  23.     reg    int    i, n;
  24.     reg    bool    count  = FALSE;
  25.     reg    bool    silent = FALSE;
  26.  
  27.     while (argc > 1 && argv[1][0] == '-')
  28.     {
  29.         for (i = 1; argv[1][i] != '\0'; i++)
  30.         {
  31.             switch (argv[1][i])
  32.             {
  33.  
  34.         when 'c':    count = TRUE;
  35.  
  36.         when 's':    silent = TRUE;
  37.  
  38.         otherwise:    usage();
  39.  
  40.             }
  41.         }
  42.  
  43.         argc--;
  44.         argv++;
  45.     }
  46.  
  47.     if (argc < 3)
  48.         usage();
  49.     
  50.     if (stat(argv[1], &statbuf) != 0)
  51.     {
  52.         sprintf(scratchbuf, "later, stat %s", argv[1]);
  53.         perror(scratchbuf);
  54.         exit(127);
  55.     }
  56.  
  57.     argv++;
  58.     argc--;
  59.     reftime = statbuf.st_mtime;
  60.     n = 0;
  61.  
  62.     while (argc > 1)
  63.     {
  64.         if (stat(argv[1], &statbuf) != 0)
  65.         {
  66.             sprintf(scratchbuf, "later, stat %s", argv[1]);
  67.             perror(scratchbuf);
  68.             exit(127);
  69.         }
  70.  
  71.         if (statbuf.st_mtime > reftime)
  72.         {
  73.             n++;
  74.             if (! silent)
  75.                 printf("%s\n", argv[1]);
  76.         }
  77.  
  78.         argc--;
  79.         argv++;
  80.     }
  81.  
  82.     exit(count? n: 0);
  83. }
  84.  
  85. /*
  86. **    Tell the unfortunate user how to use later.
  87. */
  88.  
  89. usage()
  90. {
  91.     printf("Usage: later [-cs] reffile file ...\n");
  92.     exit(1);
  93. }
  94.