home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / dos / mytouch.lzh / MYTOUCH.C next >
Encoding:
C/C++ Source or Header  |  1988-05-13  |  4.4 KB  |  140 lines

  1. /*
  2.         m y t o u c h . c
  3.  
  4.         VERSION        :        1.10
  5.         EDIT-DATE      :        12-May-88
  6.  
  7.          This program is similar to the UNIX and MS-DOS Touch functions,
  8.     except that it will also allow you to specify the date and time, as
  9.     well as use the current system date and time.
  10.  
  11.         m o d i f i c a t i o n   h i s t o r y
  12.  
  13. VERSION        EDIT-DATE        DESCRIPTION
  14. -------        ---------        -----------
  15.  1.10          12-May-88       This version allows the use of wildcards.
  16.                                It is highly recommended that you use them
  17.                                only while in the directory containing the
  18.                                file(s).
  19.  
  20.  
  21. */
  22.  
  23. #include <fcntl.h>
  24. #include <sys\types.h>
  25. #include <sys\stat.h>
  26. #include <io.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <dos.h>
  31. #include <direct.h>
  32.  
  33. main(argc, argv)
  34. int argc;
  35. char *argv[];
  36. {
  37.     register int i;
  38.     int fh, split_val, done, f_count;
  39.     char out_line[81];
  40.     char cur_fname[MAXPATH];
  41.     char drive[MAXDRIVE];
  42.     char dir[MAXDIR];
  43.     char file[MAXFILE];
  44.     char ext[MAXEXT];
  45.     struct ftime f_t;
  46.     struct time now;
  47.     struct date today;
  48.     struct ffblk ffblk;
  49.  
  50.     if (argc == 1) {
  51.         printf("USAGE:\n    mytouch <filename> [hh:mm] [mm/dd/yy]\n");
  52.         printf("You must supply the filename, Wildcards are supported\n");
  53.         printf("at this time.");
  54.         exit(1);
  55.         }
  56.     split_val = fnsplit(argv[1], drive, dir, file, ext);
  57.     done = 0;
  58.     f_count = 0;
  59.     do {
  60.         if ((split_val & WILDCARDS) == 0) {
  61.             sprintf(cur_fname, "%s", argv[1]);
  62.             done = 1;
  63.             }
  64.         else {
  65.             if (f_count == 0) {
  66.                 done = findfirst(argv[1], &ffblk, 0);
  67.                 if (done) {
  68.                     printf("\nNo matching files found\n\n");
  69.                     exit(1);
  70.                     }
  71.                 }
  72.             else {
  73.                 done = findnext(&ffblk);
  74.                 if (done) {
  75.                     printf("\nAll files processed.\n\n");
  76.                     exit(0);
  77.                     }
  78.                 }
  79.             f_count++;
  80.             sprintf(cur_fname, "%s", ffblk.ff_name);
  81.             }
  82.         if (access(cur_fname, 0x00) == -1) {
  83.             sprintf(out_line, "Error accessing %s  ",cur_fname);
  84.             perror(out_line);
  85.             exit(1);
  86.             }
  87.         if ((fh = open(cur_fname, O_RDONLY)) == -1) {
  88.             sprintf(out_line, "Error opening %s  ", cur_fname);
  89.             perror(out_line);
  90.             exit(1);
  91.             }
  92.         getftime(fh, &f_t);
  93.         if (argc > 2) {
  94. /* printf("MYTOUCH:  argc > 2  (%d)\n", argc); */
  95.             for (i=2;i<argc;i++) {
  96. /* printf("MYTOUCH:  i = %d\n", i);
  97.    printf("          strlen(argv[%d] = %d  (\"%s\")\n", i, strlen(argv[i]), argv[i]); */
  98.                 if (strlen(argv[i]) == 5 || argv[i][2] == ':') {
  99. /* printf("MYTOUCH resetting time for %s (%s)\n", cur_fname, argv[i]); */
  100.                     argv[i][2] = 0x00;
  101.                     argv[i][5] = 0x00;
  102.                     f_t.ft_hour = atoi(&argv[i][0]);
  103.                     f_t.ft_min  = atoi(&argv[i][3]);
  104.                     f_t.ft_tsec = 0;
  105.                     argv[i][2] = ':';
  106.                     }
  107.                 else if (strlen(argv[i]) == 8) {
  108. /* printf("MYTOUCH resetting date for %s (%s)\n", cur_fname, argv[i]); */
  109.                     argv[i][2] = 0x00;
  110.                     argv[i][5] = 0x00;
  111.                     argv[i][8] = 0x00;
  112.                     f_t.ft_month = atoi(&argv[i][0]);
  113.                     f_t.ft_day = atoi(&argv[i][3]);
  114.                     f_t.ft_year = atoi(&argv[i][6]) - 80;
  115.                     argv[i][2] = '/';
  116.                     argv[i][5] = '/';
  117.                     }
  118.                 }
  119.             }
  120.         else {
  121.             gettime(&now);
  122.             f_t.ft_tsec = 0;
  123.             f_t.ft_min = now.ti_min;
  124.             f_t.ft_hour = now.ti_hour;
  125.             getdate(&today);
  126.             f_t.ft_month = today.da_mon;
  127.             f_t.ft_day = today.da_day;
  128.             f_t.ft_year = today.da_year - 1980;
  129.             }
  130.         setftime(fh, &f_t);
  131.         printf("%s  %02d:%02d:%02d.00  %02d/%02d/%02d\n",
  132.                cur_fname,
  133.                f_t.ft_hour, f_t.ft_min, f_t.ft_tsec,
  134.                f_t.ft_month, f_t.ft_day, f_t.ft_year);
  135.         close(fh);
  136.         } while (!done);
  137.  
  138. }
  139.  
  140.