home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c019 / 1.ddi / ARC521_C / ARCDOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-01  |  4.9 KB  |  219 lines

  1. /*
  2.  * $Header: arcdos.c,v 1.5 88/06/13 00:40:49 hyc Locked $
  3.  */
  4.  
  5. /*
  6.  * ARC - Archive utility - ARCDOS
  7.  * 
  8.  * Version 1.44, created on 07/25/86 at 14:17:38
  9.  * 
  10.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  11.  * 
  12.  * By:  Thom Henderson
  13.  * 
  14.  * Description: This file contains certain DOS level routines that assist in
  15.  * doing fancy things with an archive, primarily reading and setting the date
  16.  * and time last modified.
  17.  * 
  18.  * These are, by nature, system dependant functions.  But they are also, by
  19.  * nature, very expendable.
  20.  * 
  21.  * Language: Computer Innovations Optimizing C86
  22.  */
  23. #include <stdio.h>
  24. #include "arc.h"
  25.  
  26. #if    MSDOS
  27. #include "fileio2.h"        /* needed for filehand */
  28. #endif
  29.  
  30. #if    UNIX
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #include <sys/time.h>
  34. #include "tws.h"
  35. #endif
  36.  
  37. #if    SYSV
  38. struct timeval {
  39.     long tv_sec;
  40.     long tv_usec;
  41. };
  42. #endif
  43.  
  44. #if    GEMDOS
  45. #include <osbind.h>
  46. #endif
  47.  
  48. char    *strcpy(), *strcat(), *malloc();
  49.  
  50. void
  51. getstamp(f, date, time)        /* get a file's date/time stamp */
  52. #if    !MTS
  53.     FILE           *f;    /* file to get stamp from */
  54. #else
  55.     char           *f;    /* filename "" "" */
  56. #endif
  57.     unsigned short   *date, *time;    /* storage for the stamp */
  58. {
  59. #if    MSDOS
  60.     struct {
  61.         int             ax, bx, cx, dx, si, di, ds, es;
  62.     }               reg;
  63.  
  64.     reg.ax = 0x5700;    /* get date/time */
  65.     reg.bx = filehand(f);    /* file handle */
  66.     if (sysint21(®, ®) & 1)    /* DOS call */
  67.         printf("Get timestamp fail (%d)\n", reg.ax);
  68.  
  69.     *date = reg.dx;        /* save date/time */
  70.     *time = reg.cx;
  71. #endif
  72. #if    GEMDOS
  73.     int    fd, ret[2];
  74.  
  75.     fd = fileno(f);
  76.     Fdatime(ret, fd, 0);
  77.     *date = ret[1];
  78.     *time = ret[0];
  79. #endif
  80. #if    UNIX
  81.     char           *ctime();
  82.     struct stat    *buf;
  83.     int             day, hr, min, sec, yr, imon;
  84.     static char     mon[4], *mons[12] = {
  85.                    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  86.                     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  87.     };
  88.  
  89.     buf = (struct stat *) malloc(sizeof(struct stat));
  90.     fstat(fileno(f), buf);
  91.  
  92.     sscanf(ctime(&(buf->st_mtime)), "%*4s%3s%d%d:%d:%d%d", mon, &day, &hr, &min,
  93.            &sec, &yr);
  94.     for (imon = 0; imon < 12 && strcmp(mon, mons[imon]); imon++);
  95.  
  96.     *date = (unsigned short) (((yr - 1980) << 9) + ((imon + 1) << 5) + day);
  97.     *time = (unsigned short) ((hr << 11) + (min << 5) + sec / 2);
  98. #endif
  99. #if    MTS
  100.     fortran         timein(),
  101. #if    USEGFINFO
  102.                     gfinfo();
  103. #else
  104.                     fileinfo();
  105. #endif
  106.     int             stclk[2];
  107.     char            name[24];
  108.     struct bigtime {
  109.         int             greg;
  110.         int             year;
  111.         int             mon;
  112.         int             day;
  113.         int             hour;
  114.         int             min;
  115.         int             sec;
  116.         int             usec;
  117.         int             week;
  118.         int             toff;
  119.         int             tzn1;
  120.         int             tzn2;
  121.     }               tvec;
  122. #if    USEGFINFO
  123.     static int      gfflag = 0x0009, gfdummy[2] = {
  124.                                0, 0
  125.     };
  126.     int             gfcinfo[18];
  127. #else
  128.     static int      cattype = 2;
  129. #endif
  130.  
  131.     strcpy(name, f);
  132.     strcat(name, " ");
  133. #if    USEGFINFO
  134.     gfcinfo[0] = 18;
  135.     gfinfo(name, name, &gfflag, gfcinfo, gfdummy, gfdummy);
  136.     timein("*IBM MICROSECONDS*", &gfcinfo[16], &tvec);
  137. #else
  138.     fileinfo(name, &cattype, "CILCCT  ", stclk);
  139.     timein("*IBM MICROSECONDS*", stclk, &tvec);
  140. #endif
  141.  
  142.     *date = (unsigned short) (((tvec.year - 1980) << 9) + ((tvec.mon) << 5) + tvec.day);
  143.     *time = (unsigned short) ((tvec.hour << 11) + (tvec.min << 5) + tvec.sec / 2);
  144. #endif
  145. }
  146.  
  147. void
  148. setstamp(f, date, time)        /* set a file's date/time stamp */
  149.     char           *f;    /* filename to stamp */
  150.     unsigned short    date, time;    /* desired date, time */
  151. {
  152. #if    MSDOS
  153.     FILE    *ff;
  154.     struct {
  155.         int             ax, bx, cx, dx, si, di, ds, es;
  156.     }               reg;
  157.  
  158.     ff = fopen(f, "w+");    /* How else can I get a handle? */
  159.  
  160.     reg.ax = 0x5701;    /* set date/time */
  161.     reg.bx = filehand(f);    /* file handle */
  162.     reg.cx = time;        /* desired time */
  163.     reg.dx = date;        /* desired date */
  164.     if (sysint21(®, ®) & 1)    /* DOS call */
  165.         printf("Set timestamp fail (%d)\n", reg.ax);
  166.     fclose(ff);
  167. #endif
  168. #if    GEMDOS
  169.     int    fd, set[2];
  170.  
  171.     fd = Fopen(f, 0);
  172.     set[0] = time;
  173.     set[1] = date;
  174.     Fdatime(set, fd, 1);
  175.     Fclose(fd);
  176. #endif
  177. #if    UNIX
  178.     struct tws      tms;
  179.     struct timeval  tvp[2];
  180.     int    utimes();
  181.     twscopy(&tms, dtwstime());
  182.     tms.tw_sec = (time & 31) * 2;
  183.     tms.tw_min = (time >> 5) & 63;
  184.     tms.tw_hour = (time >> 11);
  185.     tms.tw_mday = date & 31;
  186.     tms.tw_mon = ((date >> 5) & 15) - 1;
  187.     tms.tw_year = (date >> 9) + 80;
  188.     tms.tw_clock = 0L;
  189.     tms.tw_flags = TW_NULL;
  190.     tvp[0].tv_sec = twclock(&tms);
  191.     tvp[1].tv_sec = tvp[0].tv_sec;
  192.     tvp[0].tv_usec = tvp[1].tv_usec = 0;
  193.     utimes(f, tvp);
  194. #endif
  195. }
  196.  
  197. #if    MSDOS
  198. int
  199. filehand(stream)        /* find handle on a file */
  200.     struct bufstr  *stream;    /* file to grab onto */
  201. {
  202.     return stream->bufhand;    /* return DOS 2.0 file handle */
  203. }
  204. #endif
  205.  
  206. #if    UNIX
  207. int
  208. izadir(filename)        /* Is filename a directory? */
  209.     char           *filename;
  210. {
  211.     struct stat     buf;
  212.  
  213.     if (stat(filename, &buf) != 0)
  214.         return (0);    /* Ignore if stat fails since */
  215.     else
  216.         return (buf.st_mode & S_IFDIR);    /* bad files trapped later */
  217. }
  218. #endif
  219.