home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / OSKBox.lzh / MAILBOX / CC / latest.c < prev    next >
Text File  |  1990-01-01  |  3KB  |  113 lines

  1. /*                                                          */
  2. /*   latest - list files modified since some date           */
  3. /*                                                          */
  4. /*   Questions and comments can be addressed to:            */
  5. /*                                                          */
  6. /*        Eric Williams                                     */
  7. /*        5712 San Diego                                    */
  8. /*        El Cerrito, CA  94530                             */
  9. /*        415-526-1575 evenings/weekends                    */
  10.  
  11. #include <stdio.h>
  12. #include <direct.h>
  13. #include <dir.h>
  14. #include <errno.h>
  15.  
  16. int disk;
  17. struct direct *entry;
  18. struct {
  19.     unsigned char year, month, day, hour, min;
  20.     } limit;
  21.  
  22. main (argc, argv)
  23. int argc;
  24. char *argv[];
  25. {
  26.      int dir;
  27.      int time, date, tick;
  28.      short day;
  29.      int i, y, m, d, h, mn;
  30.  
  31.      if (argc < 2) {
  32.           printf ("form:  latest directory [MM/DD[/YY]] [HH:MM]\n");
  33.           exit (0);
  34.      }
  35.      if ((dir = open (argv[1], 0x81)) <= 0) exit (errno);
  36.      if ((disk = opendisk (dir)) <= 0) exit (errno);
  37.      close (dir);
  38.      _sysdate (0, &time, &date, &day, &tick);
  39.      y = (date >> 16) % 100;  m = (date >> 8) & 0xff;  d = date & 0xff;
  40.      limit.year = y;  limit.month = m;  limit.day = d;
  41.      limit.hour = h = 0;  limit.min = mn = 0;
  42.      for (i = 2; i < argc; i++) {
  43.           if (index (argv[i], '/')) {
  44.                sscanf (argv[2], "%d/%d/%d", &m, &d, &y);
  45.                limit.year = y;  limit.month = m;  limit.day = d;
  46.           }
  47.           if (index (argv[i], ':')) {
  48.                sscanf (argv[3], "%d:%d", &h, &mn);
  49.                limit.hour = h;  limit.min = mn;
  50.           }
  51.      }
  52.      scan (argv[1]);
  53.      close (disk);
  54. }
  55.  
  56. opendisk(path)
  57. int path;
  58. {
  59.      char dname[33];
  60.  
  61.     *dname = '/';
  62.     _gs_devn (path, dname+1);
  63.     strcat (dname, "@");
  64.     return (open (dname, 0x01));
  65. }
  66.  
  67. scan (node)
  68. char *node;
  69. {
  70.      DIR *path, *tpath;
  71.      char file[80];
  72.  
  73.      path = opendir (node);
  74.      while (entry = readdir (path))
  75.           if (entry->d_name[0] != '.') {
  76.                sprintf (file, "%s/%s", node, entry->d_name);
  77.                if (checkdate (entry, file) == -1)
  78.                     if ((tpath = opendir (file)) == NULL)
  79.                          exit (errno);
  80.                     else {
  81.                          closedir (tpath);
  82.                          scan (file);
  83.                     }
  84.           }
  85.      closedir (path);
  86.      return (0);
  87. }
  88.  
  89. checkdate (entry, filename)
  90. struct direct *entry;
  91. char *filename;
  92. {
  93.      struct fildes info;
  94.      long diskpos;
  95.  
  96.      lseek (disk, 256 * entry->d_addr, 0);
  97.      read (disk, &info, sizeof(info));
  98.      if (info.fd_att & 0x80) return (-1);
  99.      if (datecmp (&limit, info.fd_date) < 0)
  100.           printf ("%s\n", filename);
  101.      return (0);
  102. }
  103.  
  104. datecmp (a, b)
  105. unsigned char *a, *b;
  106. {
  107.      int i, c;
  108.  
  109.      for (i = 0; i < 5; i++)
  110.           if (c = *a++ - *b++) return (c);
  111.      return (0);
  112. }
  113.