home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNPD9404.ZIP / TODAYBAK.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  2KB  |  99 lines

  1. /*
  2. **  TODAYBAK.C - Back up today's work to a specified floppy
  3. **
  4. **  public domain demo by Bob Stout
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <dos.h>
  11.  
  12. #if defined(__ZTC__) && (__ZTC__ < 0x600)
  13.  #define _dos_getdate   dos_getdate
  14.  #define _dos_setdate   dos_setdate
  15.  #define _dosdate_t     dos_date_t
  16. #endif
  17. #ifdef __TURBOC__
  18.  #define _dosdate_t     dosdate_t
  19. #endif
  20.  
  21. #ifndef SUCCESS
  22.  #define SUCCESS 0
  23. #endif
  24.  
  25. #ifndef CAST
  26.  #define CAST(new_type,old_object) (*((new_type *)&(old_object)))
  27. #endif
  28.  
  29. #define LAST_CHAR(s) (((char *)s)[strlen(s) - 1])
  30.  
  31. struct DOS_DATE {
  32.         unsigned int da : 5;
  33.         unsigned int mo : 4;
  34.         unsigned int yr : 7;
  35.         } ;
  36.  
  37. struct _dosdate_t today;
  38. struct DOS_DATE   ftoday;
  39. char   drive;
  40.  
  41. void do_dir(char *);
  42. void usage(void);
  43.  
  44. int main(int argc, char *argv[])
  45. {
  46.       int i;
  47.  
  48.       _dos_getdate(&today);
  49.       ftoday.da = today.day;
  50.       ftoday.mo = today.month;
  51.       ftoday.yr = today.year - 1980;
  52.  
  53.       if (2 > argc)
  54.             usage();
  55.  
  56.       drive = *argv[1];
  57.       if (!strchr("AaBb", drive))
  58.             usage();
  59.  
  60.       if (3 > argc)
  61.             do_dir(".");
  62.       else for (i = 2; i < argc; ++i)
  63.             do_dir(argv[i]);
  64.  
  65.       return EXIT_SUCCESS;
  66. }
  67.  
  68. void usage(void)
  69. {
  70.       puts("usage: TODAYBAK floppy [dir1] [...dirN]");
  71.       puts("       Copies today's files to the specified floppy.");
  72.       puts("       floppy = 'A' | 'B'");
  73.       puts("       with no directories specified, "
  74.             "uses current directory");
  75.       exit(EXIT_FAILURE);
  76. }
  77.  
  78. void do_dir(char *path)
  79. {
  80.       char search[67];
  81.       struct find_t ff;
  82.  
  83.       strcat(strcpy(search, path), "\\*.*");
  84.       if (SUCCESS == _dos_findfirst(search, 0xff, &ff)) do
  85.       {
  86.             if (!(ff.attrib & _A_SUBDIR) && '.' != *ff.name)
  87.             {
  88.                   if (ff.wr_date == CAST(unsigned short, ftoday))
  89.                   {
  90.                         char cmd[128];
  91.  
  92.                         sprintf(cmd, "COPY %s\\%s %c: > NUL",
  93.                               path, ff.name, drive);
  94.                         system(cmd);
  95.                   }
  96.             }
  97.       } while (SUCCESS == _dos_findnext(&ff));
  98. }
  99.