home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip51.zip / tops20 / tops20.c < prev   
C/C++ Source or Header  |  1993-10-08  |  5KB  |  205 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   tops20.c
  4.  
  5.   TOPS20-specific routines for use with Info-ZIP's UnZip 5.1 and later.
  6.  
  7.   ---------------------------------------------------------------------------*/
  8.  
  9.  
  10. #include "unzip.h"
  11.  
  12.  
  13. /**********************/
  14. /* Function mapattr() */
  15. /**********************/
  16.  
  17. int mapattr()      /* just like Unix except no umask() */
  18. {
  19.     ulg  tmp = crec.external_file_attributes;
  20.  
  21.     switch (pInfo->hostnum) {
  22.         case UNIX_:
  23.         case VMS_:
  24.             pInfo->file_attr = (unsigned)(tmp >> 16);
  25.             break;
  26.         case AMIGA_:
  27.             tmp = (unsigned)(tmp>>1 & 7);   /* Amiga RWE bits */
  28.             pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
  29.             break;
  30.         case FS_FAT_:   /* MSDOS half of attributes should always be correct */
  31.         case FS_HPFS_:
  32.         case FS_NTFS_:
  33.         case MAC_:
  34.         case ATARI_:
  35.         case TOPS20_:
  36.         default:
  37.             tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
  38.             pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
  39.             break;
  40. #if 0
  41.         case ATARI_:
  42.         case TOPS20_:
  43.         default:
  44.             pInfo->file_attr = 0666;
  45.             break;
  46. #endif
  47.     } /* end switch (host-OS-created-by) */
  48.  
  49.     return 0;
  50.  
  51. } /* end function mapattr() */
  52.  
  53.  
  54.  
  55.  
  56.  
  57. /****************************/
  58. /* Function close_outfile() */
  59. /****************************/
  60.  
  61. void close_outfile()
  62. {
  63. #   define JSYS_CLASS           0070000000000
  64. #   define FLD(val,mask)        (((unsigned)(val)*((mask)&(-(mask))))&(mask))
  65. #   define _DEFJS(name,class)   (FLD(class,JSYS_CLASS) | (monsym(name)&0777777))
  66. #   define IDTIM                _DEFJS("IDTIM%", 1)
  67. #   define SFTAD                _DEFJS("SFTAD%", 0)
  68. #   define YRBASE               1900
  69.     int ablock[5], tblock[2];
  70.     int yr, mo, dy, hh, mm, ss;
  71.     char temp[100];
  72.     unsigned tad;
  73.  
  74.  
  75.     /* dissect the date */
  76.     yr = ((lrec.last_mod_file_date >> 9) & 0x7f) + (1980 - YRBASE);
  77.     mo = (lrec.last_mod_file_date >> 5) & 0x0f;
  78.     dy = lrec.last_mod_file_date & 0x1f;
  79.  
  80.     /* dissect the time */
  81.     hh = (lrec.last_mod_file_time >> 11) & 0x1f;
  82.     mm = (lrec.last_mod_file_time >> 5) & 0x3f;
  83.     ss = (lrec.last_mod_file_time & 0x1f) * 2;
  84.     
  85.     sprintf(temp, "%02d/%02d/%02d %02d:%02d:%02d", mo, dy, yr, hh, mm, ss);
  86.  
  87.     ablock[1] = (int)(temp - 1);
  88.     ablock[2] = 0;
  89.     if (!jsys(IDTIM, ablock)) {
  90.         fprintf(stderr, "error:  IDTIM failure for %s\n", filename);
  91.         fclose(outfile);
  92.         return;
  93.     }
  94.  
  95.     tad = ablock[2];
  96.     tblock[0] = tad;
  97.     tblock[1] = tad;
  98.     tblock[2] = -1;
  99.  
  100.     ablock[1] = fcntl(fileno(outfile), F_GETSYSFD, 0); /* _uffd[outfd]->uf_ch */
  101.     ablock[2] = (int) tblock;
  102.     ablock[3] = 3;
  103.     if (!jsys(SFTAD, ablock))
  104.         fprintf(stderr, "error:  can't set the time for %s\n", filename);
  105.  
  106.     fclose(outfile);
  107.  
  108. } /* end function close_outfile() */
  109.  
  110.  
  111.  
  112.  
  113.  
  114. /**********************/
  115. /*  Function upper()  */
  116. /**********************/
  117.  
  118. int upper(s)        /* returns s in uppercase */
  119.     char *s;        /* string to be uppercased */
  120. {
  121.     for (;  *s;  ++s)
  122.         *s = toupper(*s);
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129. /************************/
  130. /*  Function enquote()  */
  131. /************************/
  132.  
  133. int enquote(s)      /* calls dequote(s) to normalize string, then */
  134.     char *s;        /*  inserts ^Vs before otherwise illegal characters */
  135. {                   /*  in s, assuming that s is a TOPS-20 filename */
  136.     char d[100];
  137.     char *p, *q;
  138.     char c;
  139.  
  140.     if (s && *s) {
  141.         dequote(s);
  142.         p = s - 1;
  143.         q = d - 1;
  144.         while (c = *++p) {
  145.             if (!fnlegal(c))
  146.                 *++q = '\026';
  147.             *++q = c;
  148.         }
  149.         *++q = '\0';
  150.         strcpy(s, d);
  151.     }
  152.     return 0;
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159. /************************/
  160. /*  Function dequote()  */
  161. /************************/
  162.  
  163. int dequote(s)        /* returns s without ^Vs */
  164.     char *s;          /* string to be dequoted */
  165. {
  166.     char d[100];
  167.     char *p, *q;
  168.     int c;
  169.  
  170.     if (s && *s) {
  171.         p = s - 1;
  172.         q = d - 1;
  173.         while (c = *++p)
  174.             if (c != '\026')
  175.                 *++q = c;
  176.         *++q = '\0';
  177.         strcpy(s, d);
  178.     }
  179.     return 0;
  180. }
  181.  
  182.  
  183.  
  184.  
  185.  
  186. /************************/
  187. /*  Function fnlegal()  */
  188. /************************/
  189.  
  190. int fnlegal(c)         /* returns TRUE if c is a member of the */
  191.     char c;            /*  legal character set for filenames */
  192. {
  193.     char *q;
  194.     static char *legals = {"$%**-<>>AZ[[]]__az"};
  195.  
  196.     q = legals;
  197.     while (*q)
  198.         if (c < *q++)
  199.             break;
  200.         else if (c <= *q++)
  201.             return TRUE;
  202.  
  203.     return FALSE;
  204. }
  205.