home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / arcppc / src / rcs / arcdos.c,v < prev    next >
Text File  |  1998-04-23  |  9KB  |  527 lines

  1. head     1.8;
  2. branch   ;
  3. access   ;
  4. symbols  patch2:1.8 patch1:1.6;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.8
  10. date     88.08.01.15.07.15;  author hyc;  state Exp;
  11. branches ;
  12. next     1.7;
  13.  
  14. 1.7
  15. date     88.08.01.14.32.06;  author hyc;  state Exp;
  16. branches ;
  17. next     1.6;
  18.  
  19. 1.6
  20. date     88.07.31.18.48.09;  author hyc;  state Exp;
  21. branches ;
  22. next     1.5;
  23.  
  24. 1.5
  25. date     88.06.13.00.40.49;  author hyc;  state Exp;
  26. branches ;
  27. next     1.4;
  28.  
  29. 1.4
  30. date     88.06.01.19.17.43;  author hyc;  state Exp;
  31. branches ;
  32. next     1.3;
  33.  
  34. 1.3
  35. date     88.06.01.15.27.01;  author hyc;  state Exp;
  36. branches ;
  37. next     1.2;
  38.  
  39. 1.2
  40. date     88.06.01.15.21.53;  author hyc;  state Exp;
  41. branches ;
  42. next     1.1;
  43.  
  44. 1.1
  45. date     88.04.11.17.53.31;  author hyc;  state Exp;
  46. branches ;
  47. next     ;
  48.  
  49.  
  50. desc
  51. @@
  52.  
  53.  
  54. 1.8
  55. log
  56. @Stick timeval definition into UNIX conditionals
  57. @
  58. text
  59. @/*
  60.  * $Header: arcdos.c,v 1.7 88/08/01 14:32:06 hyc Locked $
  61.  */
  62.  
  63. /*
  64.  * ARC - Archive utility - ARCDOS
  65.  * 
  66.  * Version 1.44, created on 07/25/86 at 14:17:38
  67.  * 
  68.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  69.  * 
  70.  * By:  Thom Henderson
  71.  * 
  72.  * Description: This file contains certain DOS level routines that assist in
  73.  * doing fancy things with an archive, primarily reading and setting the date
  74.  * and time last modified.
  75.  * 
  76.  * These are, by nature, system dependant functions.  But they are also, by
  77.  * nature, very expendable.
  78.  * 
  79.  * Language: Computer Innovations Optimizing C86
  80.  */
  81. #include <stdio.h>
  82. #include "arc.h"
  83.  
  84. #if    MSDOS
  85. #include "fileio2.h"        /* needed for filehand */
  86. #endif
  87.  
  88. #if    UNIX
  89. #include <sys/types.h>
  90. #include <sys/stat.h>
  91. #include <time.h>
  92.  
  93. struct timeval {    /* man page said <sys/types.h>, but it */
  94.     long tv_sec;    /* really seems to be in <sys/time.h>, */
  95.     long tv_usec;    /* but why bother... */
  96. };
  97. #endif
  98.  
  99. #if    GEMDOS
  100. #include <osbind.h>
  101. #endif
  102.  
  103. char    *strcpy(), *strcat(), *malloc();
  104.  
  105. void
  106. getstamp(f, date, time)        /* get a file's date/time stamp */
  107. #if    !MTS
  108.     FILE           *f;    /* file to get stamp from */
  109. #else
  110.     char           *f;    /* filename "" "" */
  111. #endif
  112.     unsigned short   *date, *time;    /* storage for the stamp */
  113. {
  114. #if    MSDOS
  115.     struct {
  116.         int             ax, bx, cx, dx, si, di, ds, es;
  117.     }               reg;
  118.  
  119.     reg.ax = 0x5700;    /* get date/time */
  120.     reg.bx = filehand(f);    /* file handle */
  121.     if (sysint21(®, ®) & 1)    /* DOS call */
  122.         printf("Get timestamp fail (%d)\n", reg.ax);
  123.  
  124.     *date = reg.dx;        /* save date/time */
  125.     *time = reg.cx;
  126. #endif
  127. #if    GEMDOS
  128.     int    fd, ret[2];
  129.  
  130.     fd = fileno(f);
  131.     Fdatime(ret, fd, 0);
  132.     *date = ret[1];
  133.     *time = ret[0];
  134. #endif
  135. #if    UNIX
  136.     struct stat    buf;
  137.     struct tm    *localtime(), *t;
  138.  
  139.     fstat(fileno(f), &buf);
  140.     t=localtime(&(buf.st_mtime));
  141.     *date = (unsigned short) (((t->tm_year - 80) << 9) +
  142.                 ((t->tm_mon + 1) << 5) + t->tm_mday);
  143.     *time = (unsigned short) ((t->tm_hour << 11) +
  144.                 (t->tm_min << 5) + t->tm_sec / 2);
  145. #endif
  146. #if    MTS
  147.     fortran         timein(),
  148. #if    USEGFINFO
  149.                     gfinfo();
  150. #else
  151.                     fileinfo();
  152. #endif
  153.     int             stclk[2];
  154.     char            name[24];
  155.     struct bigtime {
  156.         int             greg;
  157.         int             year;
  158.         int             mon;
  159.         int             day;
  160.         int             hour;
  161.         int             min;
  162.         int             sec;
  163.         int             usec;
  164.         int             week;
  165.         int             toff;
  166.         int             tzn1;
  167.         int             tzn2;
  168.     }               tvec;
  169. #if    USEGFINFO
  170.     static int      gfflag = 0x0009, gfdummy[2] = {
  171.                                0, 0
  172.     };
  173.     int             gfcinfo[18];
  174. #else
  175.     static int      cattype = 2;
  176. #endif
  177.  
  178.     strcpy(name, f);
  179.     strcat(name, " ");
  180. #if    USEGFINFO
  181.     gfcinfo[0] = 18;
  182.     gfinfo(name, name, &gfflag, gfcinfo, gfdummy, gfdummy);
  183.     timein("*IBM MICROSECONDS*", &gfcinfo[16], &tvec);
  184. #else
  185.     fileinfo(name, &cattype, "CILCCT  ", stclk);
  186.     timein("*IBM MICROSECONDS*", stclk, &tvec);
  187. #endif
  188.  
  189.     *date = (unsigned short) (((tvec.year - 1980) << 9) + ((tvec.mon) << 5) + tvec.day);
  190.     *time = (unsigned short) ((tvec.hour << 11) + (tvec.min << 5) + tvec.sec / 2);
  191. #endif
  192. }
  193.  
  194. void
  195. setstamp(f, date, time)        /* set a file's date/time stamp */
  196.     char           *f;    /* filename to stamp */
  197.     unsigned short    date, time;    /* desired date, time */
  198. {
  199. #if    MSDOS
  200.     FILE    *ff;
  201.     struct {
  202.         int             ax, bx, cx, dx, si, di, ds, es;
  203.     }               reg;
  204.  
  205.     ff = fopen(f, "w+");    /* How else can I get a handle? */
  206.  
  207.     reg.ax = 0x5701;    /* set date/time */
  208.     reg.bx = filehand(f);    /* file handle */
  209.     reg.cx = time;        /* desired time */
  210.     reg.dx = date;        /* desired date */
  211.     if (sysint21(®, ®) & 1)    /* DOS call */
  212.         printf("Set timestamp fail (%d)\n", reg.ax);
  213.     fclose(ff);
  214. #endif
  215. #if    GEMDOS
  216.     int    fd, set[2];
  217.  
  218.     fd = Fopen(f, 0);
  219.     set[0] = time;
  220.     set[1] = date;
  221.     Fdatime(set, fd, 1);
  222.     Fclose(fd);
  223. #endif
  224. #if    UNIX
  225.     struct tm    tm;
  226.     struct timeval  tvp[2];
  227.     int    utimes();
  228.     tm.tm_sec = (time & 31) * 2;
  229.     tm.tm_min = (time >> 5) & 63;
  230.     tm.tm_hour = (time >> 11);
  231.     tm.tm_mday = date & 31;
  232.     tm.tm_mon = ((date >> 5) & 15) - 1;
  233.     tm.tm_year = (date >> 9) + 80;
  234.     tvp[0].tv_sec = tmclock(&tm);
  235.     tvp[1].tv_sec = tvp[0].tv_sec;
  236.     tvp[0].tv_usec = tvp[1].tv_usec = 0;
  237.     utimes(f, tvp);
  238. #endif
  239. }
  240.  
  241. #if    MSDOS
  242. int
  243. filehand(stream)        /* find handle on a file */
  244.     struct bufstr  *stream;    /* file to grab onto */
  245. {
  246.     return stream->bufhand;    /* return DOS 2.0 file handle */
  247. }
  248. #endif
  249.  
  250. #if    UNIX
  251. int
  252. izadir(filename)        /* Is filename a directory? */
  253.     char           *filename;
  254. {
  255.     struct stat     buf;
  256.  
  257.     if (stat(filename, &buf) != 0)
  258.         return (0);    /* Ignore if stat fails since */
  259.     else
  260.         return (buf.st_mode & S_IFDIR);    /* bad files trapped later */
  261. }
  262. #endif
  263. @
  264.  
  265.  
  266. 1.7
  267. log
  268. @Fix up include file dependency, use tmclock() instead of twsclock().
  269. @
  270. text
  271. @d2 1
  272. a2 1
  273.  * $Header: arcdos.c,v 1.6 88/07/31 18:48:09 hyc Locked $
  274. a33 1
  275. #endif
  276. d39 1
  277. @
  278.  
  279.  
  280. 1.6
  281. log
  282. @Fixup time processing, fix a typo in declarations, fix args
  283. to fopen...
  284. @
  285. text
  286. @d2 1
  287. a2 1
  288.  * $Header: arcdos.c,v 1.5 88/06/13 00:40:49 hyc Locked $
  289. d33 1
  290. a33 2
  291. #include <sys/time.h>
  292. #include "tws.h"
  293. d36 3
  294. a38 5
  295. #if    SYSV
  296. #include <sys/times.h>
  297. struct timeval {
  298.     long tv_sec;
  299.     long tv_usec;
  300. a39 1
  301. #endif
  302. d167 1
  303. a167 1
  304.     struct tws      tms;
  305. d170 7
  306. a176 10
  307.     twscopy(&tms, dtwstime());
  308.     tms.tw_sec = (time & 31) * 2;
  309.     tms.tw_min = (time >> 5) & 63;
  310.     tms.tw_hour = (time >> 11);
  311.     tms.tw_mday = date & 31;
  312.     tms.tw_mon = ((date >> 5) & 15) - 1;
  313.     tms.tw_year = (date >> 9) + 80;
  314.     tms.tw_clock = 0L;
  315.     tms.tw_flags = TW_NULL;
  316.     tvp[0].tv_sec = twclock(&tms);
  317. @
  318.  
  319.  
  320. 1.5
  321. log
  322. @Changed setstamp's mechanics a little bit...
  323. Uses a filename now, instead of a descriptor.
  324. @
  325. text
  326. @d2 1
  327. a2 1
  328.  * $Header: arcdos.c,v 1.4 88/06/01 19:17:43 hyc Locked $
  329. d38 1
  330. d82 2
  331. a83 6
  332.     struct stat    *buf;
  333.     int             day, hr, min, sec, yr, imon;
  334.     static char     mon[4], *mons[12] = {
  335.                    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  336.                     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  337.     };
  338. d85 6
  339. a90 9
  340.     buf = (struct stat *) malloc(sizeof(struct stat));
  341.     fstat(fileno(f), buf);
  342.  
  343.     sscanf(ctime(&(buf->st_mtime)), "%*4s%3s%d%d:%d:%d%d", mon, &day, &hr, &min,
  344.            &sec, &yr);
  345.     for (imon = 0; imon < 12 && strcmp(mon, mons[imon]); imon++);
  346.  
  347.     *date = (unsigned short) (((yr - 1980) << 9) + ((imon + 1) << 5) + day);
  348.     *time = (unsigned short) ((hr << 11) + (min << 5) + sec / 2);
  349. d173 1
  350. @
  351.  
  352.  
  353. 1.4
  354. log
  355. @Change compilation conditionals
  356. @
  357. text
  358. @d2 1
  359. a2 1
  360.  * $Header: arcdos.c,v 1.3 88/06/01 15:27:01 hyc Locked $
  361. a147 1
  362. #if    !MSDOS
  363. a148 3
  364. #else
  365.     FILE           *f;    /* file to set stamp on */
  366. #endif
  367. d152 1
  368. d157 1
  369. a157 1
  370.     fflush(f);        /* force any pending output */
  371. d165 1
  372. d187 1
  373. @
  374.  
  375.  
  376. 1.3
  377. log
  378. @Merge Atari ST code
  379. @
  380. text
  381. @d2 1
  382. a2 1
  383.  * $Header: arcdos.c,v 1.2 88/06/01 15:21:53 hyc Locked $
  384. d26 1
  385. a26 1
  386. #ifdef MSDOS
  387. d30 1
  388. a30 1
  389. #ifdef BSD
  390. d37 1
  391. a37 1
  392. #ifdef SYSV
  393. d44 1
  394. a44 1
  395. #ifdef    GEMDOS
  396. d52 1
  397. a52 1
  398. #ifndef MTS
  399. d59 1
  400. a59 1
  401. #ifdef MSDOS
  402. d72 1
  403. a72 1
  404. #ifdef    GEMDOS
  405. d80 1
  406. a80 1
  407. #ifdef BSD
  408. d98 1
  409. a98 1
  410. #ifdef MTS
  411. d100 1
  412. a100 1
  413. #ifdef USEGFINFO
  414. d121 1
  415. a121 1
  416. #ifdef USEGFINFO
  417. d132 1
  418. a132 1
  419. #ifdef USEGFINFO
  420. d148 1
  421. a148 1
  422. #ifndef  MSDOS
  423. d155 1
  424. a155 1
  425. #ifdef MSDOS
  426. d169 1
  427. a169 1
  428. #ifdef GEMDOS
  429. d178 1
  430. a178 1
  431. #ifdef BSD
  432. d196 1
  433. a196 1
  434. #ifdef MSDOS
  435. d205 1
  436. a205 1
  437. #ifdef    BSD
  438. @
  439.  
  440.  
  441. 1.2
  442. log
  443. @Fixed declarations
  444. @
  445. text
  446. @d2 1
  447. a2 1
  448.  * $Header: arcdos.c,v 1.8 88/04/19 01:39:36 hyc Exp $
  449. d44 4
  450. d72 8
  451. d148 1
  452. a148 1
  453. #ifdef  BSD
  454. d169 9
  455. d205 1
  456. a209 3
  457. #ifndef BSD
  458.     return (0);
  459. #else
  460. d216 1
  461. a217 1
  462. }
  463. @
  464.  
  465.  
  466. 1.1
  467. log
  468. @Initial revision
  469. @
  470. text
  471. @d2 1
  472. a2 14
  473.  * $Log:    arcdos.c,v $
  474.  * Revision 1.2  87/12/19  04:20:26  hyc
  475.  * Replace reference to f->_file with fileno(f)
  476.  * 
  477.  * Revision 1.1  87/12/19  04:19:40  hyc
  478.  * Initial revision
  479.  * 
  480.  * Revision 1.4  87/08/13  17:03:16  hyc
  481.  * Run thru the indent program...
  482.  *  Revision 1.3  87/07/21  11:40:35  hyc *** empty
  483.  * log message ***
  484.  * 
  485.  * Revision 1.2  87/07/21  07:22:17  hyc added BSD goodies
  486.  * 
  487. d25 1
  488. d29 1
  489. d37 10
  490. a46 1
  491. INT
  492. d48 1
  493. a48 1
  494. #  ifndef MTS
  495. d53 1
  496. a53 1
  497.     unsigned INT   *date, *time;    /* storage for the stamp */
  498. d83 2
  499. a84 2
  500.     *date = (unsigned INT) (((yr - 1980) << 9) + ((imon + 1) << 5) + day);
  501.     *time = (unsigned INT) ((hr << 11) + (min << 5) + sec / 2);
  502. d129 2
  503. a130 2
  504.     *date = (unsigned INT) (((tvec.year - 1980) << 9) + ((tvec.mon) << 5) + tvec.day);
  505.     *time = (unsigned INT) ((tvec.hour << 11) + (tvec.min << 5) + tvec.sec / 2);
  506. d134 1
  507. a134 1
  508. INT
  509. d136 1
  510. a136 1
  511. #  ifdef  BSD
  512. d141 1
  513. a141 1
  514.     unsigned INT    date, time;    /* desired date, time */
  515. d175 2
  516. a176 1
  517. INT
  518. a179 1
  519. #ifdef MSDOS
  520. d181 1
  521. a182 1
  522. }
  523. d184 1
  524. a184 1
  525. INT
  526. @
  527.